|
| 1 | +/* |
| 2 | + * Automato "Hello World" |
| 3 | + * - Blink an LED |
| 4 | + * - Print to serial |
| 5 | + * - Read the Temperature sensor |
| 6 | + * - Display the temperature on the screen |
| 7 | + * |
| 8 | + * Chris Chronopoulos 20210721 |
| 9 | + |
| 10 | + * |
| 11 | + */ |
| 12 | +#include "SPI.h" |
| 13 | +#include "Adafruit_GFX.h" |
| 14 | +#include "Adafruit_ILI9341.h" |
| 15 | + |
| 16 | +#include "SparkFun_SHTC3.h" |
| 17 | + |
| 18 | + |
| 19 | +Adafruit_ILI9341 tft = Adafruit_ILI9341(PIN_LCD_CS, PIN_LCD_DC, MOSI, SCK, PIN_LCD_RST, MISO); |
| 20 | +SHTC3 shtc3; |
| 21 | +float temperature, humidity; |
| 22 | + |
| 23 | +void setup() { |
| 24 | + |
| 25 | + // user LED |
| 26 | + pinMode(PIN_LED, OUTPUT); |
| 27 | + |
| 28 | + // USB serial |
| 29 | + Serial.begin(115200); |
| 30 | + while(!Serial) |
| 31 | + |
| 32 | + // LCD |
| 33 | + pinMode(PIN_LED_LCD, OUTPUT); |
| 34 | + digitalWrite(PIN_LED_LCD, HIGH); |
| 35 | + tft.begin(); |
| 36 | + tft.setRotation(1); |
| 37 | + |
| 38 | + // SHTC3 |
| 39 | + Wire.begin(); |
| 40 | + shtc3.begin(); |
| 41 | + |
| 42 | + delay(1000); |
| 43 | + Serial.println("hello world!"); |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +void updateLCD() { |
| 48 | + |
| 49 | + tft.fillScreen(ILI9341_BLACK); |
| 50 | + |
| 51 | + tft.setCursor(0,0); |
| 52 | + tft.setTextColor(ILI9341_GREEN); |
| 53 | + tft.setTextSize(4); |
| 54 | + tft.println("Hello World!"); |
| 55 | + tft.println(); |
| 56 | + |
| 57 | + tft.setTextSize(2); |
| 58 | + |
| 59 | + tft.setTextColor(ILI9341_RED); |
| 60 | + tft.print("Temperature = "); |
| 61 | + tft.print(temperature); |
| 62 | + tft.println(" F"); |
| 63 | + tft.println(); |
| 64 | + |
| 65 | + tft.setTextColor(ILI9341_BLUE); |
| 66 | + tft.print("Humidity = "); |
| 67 | + tft.print(humidity); |
| 68 | + tft.println("%"); |
| 69 | + tft.println(); |
| 70 | + |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +void loop() { |
| 75 | + |
| 76 | + // get a reading from the temp/humidity sensor |
| 77 | + shtc3.update(); |
| 78 | + temperature = shtc3.toDegF(); |
| 79 | + humidity = shtc3.toPercent(); |
| 80 | + |
| 81 | + // output to serial |
| 82 | + Serial.print("RH = "); |
| 83 | + Serial.print(shtc3.toPercent()); |
| 84 | + Serial.print("%, T = "); |
| 85 | + Serial.print(shtc3.toDegF()); |
| 86 | + Serial.println(" deg F"); |
| 87 | + |
| 88 | + // output to LCD |
| 89 | + updateLCD(); |
| 90 | + |
| 91 | + // blinky blink |
| 92 | + digitalWrite(PIN_LED, HIGH); // turn the LED on (HIGH is the voltage level) |
| 93 | + delay(1000); // wait for a second |
| 94 | + digitalWrite(PIN_LED, LOW); // turn the LED off by making the voltage LOW |
| 95 | + delay(1000); |
| 96 | + |
| 97 | +} |
0 commit comments