본문 바로가기
Useful IT

[MICROBIT] 1.8 INCH LCD 예제 - #1. 온도계와 그래프

by 이미존재 2023. 2. 13.
반응형

 

■ Microbit 1.8inch LCD 온도계 예제


※1.8inch LCD를 구매 했는데 활용 소스를 찾다가 유튜브에 나온 영상을 보고 작성한 예제입니다.
※LCD는 LCD모듈 WK-MBA-M001 제품을 사용했습니다.(Waveshare보다 저가 제품입니다.)
※확장라이브러리는 1.8inch LCD for Waveshare 입니다.
https://github.com/waveshare/WSLCD1in8

 

GitHub - waveshare/WSLCD1in8

Contribute to waveshare/WSLCD1in8 development by creating an account on GitHub.

github.com


1. 예제 내용

- 온도센서를 이용해 최대 온도와 최소 온도를 표현
- 선을 이용한 온도 그래프 출력
- 플레이 동영상


2. LCD display에 출력하기 예제 참고

http://www.suppertime.co.uk/blogmywiki/2019/11/microbit-colour-lcd/

 

LCD colour display for micro:bit | Blog My Wiki!

LCD colour display for micro:bit I love displays so I couldn’t resist this £10 Waveshare colour LCD that plugs straight into the micro:bit’s edge connector. It’s small, 1.8 inches across, and with a resolution of 160×128 pixels, but just the right

www.suppertime.co.uk


3. 예제 헥사 코드

 

microbit-temp.hex
1.26MB
블럭코드 버전으로 일부만 캡쳐

 

4. 자바스크립트 코드

input.onButtonPressed(Button.A, function () {
    max = input.temperature()
    min = input.temperature()
})
let temp = 0
let min = 0
let max = 0
LCD1IN8.LCD_Init()
LCD1IN8.LCD_Clear()
LCD1IN8.LCD_Filling(LCD1IN8.Get_Color(LCD_COLOR.WHITE))
LCD1IN8.LCD_SetBL(123)
max = input.temperature()
min = input.temperature()
let x = 1
let black = true
let color = 0
basic.forever(function () {
    temp = input.temperature()
    if (temp > max) {
        max = temp
    } else if (temp < min) {
        min = temp
    }
    LCD1IN8.DrawRectangle(
    1,
    1,
    80,
    43,
    LCD1IN8.Get_Color(LCD_COLOR.WHITE),
    DRAW_FILL.DRAW_FULL,
    DOT_PIXEL.DOT_PIXEL_1
    )
    LCD1IN8.DisString(
    2,
    1,
    "Temp now" + temp,
    LCD1IN8.Get_Color(LCD_COLOR.BLACK)
    )
    LCD1IN8.DisString(
    2,
    15,
    "MAX" + max,
    LCD1IN8.Get_Color(LCD_COLOR.RED)
    )
    LCD1IN8.DisString(
    2,
    30,
    "MIN" + min,
    LCD1IN8.Get_Color(LCD_COLOR.BLUE)
    )
    LCD1IN8.LCD_DisplayWindows(
    1,
    1,
    80,
    42
    )
    LCD1IN8.DrawRectangle(
    x,
    45,
    x + 1,
    128,
    LCD1IN8.Get_Color(LCD_COLOR.WHITE),
    DRAW_FILL.DRAW_FULL,
    DOT_PIXEL.DOT_PIXEL_1
    )
    LCD1IN8.DrawLine(
    x,
    128,
    x,
    128 - temp * 2,
    color,
    DOT_PIXEL.DOT_PIXEL_1,
    LINE_STYLE.LINE_SOLID
    )
    LCD1IN8.LCD_DisplayWindows(
    x - 1,
    45,
    x + 1,
    128
    )
    x += 1
    if (x > 160) {
        x = 1
        if (black) {
            color = 2016
        } else {
            color = 0
        }
        black = !(black)
    }
})

 

5. 실행 동영상

728x90

댓글