Seongbin Lim
/
sb_first_project
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
main.cpp
- Committer:
- sb8718
- Date:
- 2020-05-22
- Revision:
- 136:53a83b91854c
- Parent:
- 135:03997cc206a4
- Child:
- 137:81b5a1672c6a
File content as of revision 136:53a83b91854c:
#include "mbed.h" #include "Adafruit_SSD1306.h" #define ADT7420_TEMP_REG (0x00) #define ADT7420_CONF_REG (0x03) #define EVAL_ADT7420_ADDR (0x48) I2C i2c(I2C_SDA, I2C_SCL); RawSerial pc(PA_2, PA_3, 115200); Adafruit_SSD1306_SPI goled(D11, D13, D10, D4, D7, 64, 128); int main() { int status; float temp; char data_write[2]; char data_read[2]; i2c.frequency(100000); data_write[0] = ADT7420_CONF_REG; data_write[1] = 0x40; status = i2c.write((EVAL_ADT7420_ADDR<<1), data_write, 2); if(status!=0) { pc.printf("I2C configuration error!\r\n"); while(1){ } } goled.clearDisplay(); goled.splash(); ThisThread::sleep_for(3000); goled.clearDisplay(); goled.setTextSize(2); goled.printf("OLED Lab.\r\n"); goled.setTextSize(1); goled.printf("HGU in Pohang \r\n\r\n"); int16_t cursor_x = goled.cursor_x; int16_t cursor_y = goled.cursor_y; while(1) { goled.setTextCursor(cursor_x,cursor_y); data_write[0] = ADT7420_TEMP_REG; i2c.write((EVAL_ADT7420_ADDR<<1),data_write,1,0); i2c.read((EVAL_ADT7420_ADDR<<1 | 0x01), data_read, 2, 0); int tempval = ((int) data_read[0]<<8 | data_read[1]); tempval >>= 3; if((tempval & 0x1000) > 0) { temp = (tempval - 8192)/16.0; } else { temp = tempval/16.0; } pc.printf("Temperature: %0.4f\r\n", temp); goled.printf("Temperature: %0.4f\r\n", temp); goled.display(); ThisThread::sleep_for(1000); } }