#include #include #include /* Arduino TFT text example This example demonstrates how to draw text on the TFT with an Arduino. This example code is in the public domain Created 15 April 2013 by Scott Fitzgerald http://arduino.cc/en/Tutorial/TFTDisplayText Modded by Steve Spence of http://arduinotronics.blogspot.com */ // Pins SCLK and MOSI are fixed in hardware, and pin 10 (or 53) // must be an output #define sclk 13 // for MEGAs use pin 52 #define mosi 11 // for MEGAs use pin 51 #define cs 10 // for MEGAs you probably want this to be pin 53 #define dc 9 #define rst 8 // you can also connect this to the Arduino reset #define PIN 5 // Digital PIN used on the Arduino #define NUMPIXELS 24 // number of LEDs in the ring #define LED_BRIGHTNESS 255 // general brightness of the LEDs from 0-255 // pin definition for the Leonardo // #define cs 7 // #define dc 0 // #define rst 1 Adafruit_NeoPixel ring = Adafruit_NeoPixel(NUMPIXELS,PIN5,NEO_GRB + NEO_KHZ800); uint32_t ledBaseColors[] = { ring.Color(LED_BRIGHTNESS, 0, 0), // red ring.Color(0, 0, LED_BRIGHTNESS), // blue ring.Color(LED_BRIGHTNESS, LED_BRIGHTNESS, 0), // yellow ring.Color(LED_BRIGHTNESS, 0, LED_BRIGHTNESS), // purple ring.Color(0, LED_BRIGHTNESS, LED_BRIGHTNESS), // cyan ring.Color(LED_BRIGHTNESS, LED_BRIGHTNESS, LED_BRIGHTNESS) // white }; // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); // char array to print to the screen char tempPrintout[6]; char humPrintout[6]; // Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain // Fahrenheit conversion added by Steve Spence, http://arduinotronics.blogspot.com #include "DHT.h" //https://learn.adafruit.com/dht/downloads #define DHTPIN A0 // what pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin + (middle) of the sensor to +5V // Connect pin S (on the right) of the sensor to whatever your DHTPIN is // Connect pin - (on the left) of the sensor to GROUND // Connect 10k resistor between S and + int cycleTime = 2000; DHT dht(DHTPIN, DHTTYPE); float h; float t; void setup() { // ring.begin(); randomSeed(analogRead(0)); // Put this line at the beginning of every sketch that uses the GLCD: TFTscreen.begin(); // clear the screen with a black background TFTscreen.background(0, 0, 0); // write the static text to the screen // set the font color to white TFTscreen.stroke(255,255,255); // set the font size TFTscreen.setTextSize(2); // write the text to the top left corner of the screen TFTscreen.text("Temperatur(C)",0,0); // write the text to the top left corner of the screen TFTscreen.text("Feuchte(%)",0,50); // ste the font size very large for the loop TFTscreen.setTextSize(2); dht.begin(); } void loop() { { resetRing(); delay(3000); simpleCircling(); tailCircling(); pairCircling(); colorWipe(); randomFlashes(); flash(); randomColors(); rainbow(); alternatingColors(); alternateLeds(); pendulum(); fire(); } //void fire() { int generation = 0; byte i = 0; uint32_t ledColor; uint8_t r, g, b; for (generation = 0; generation < 150; generation++) { // set some hotspots if (generation % 5 == 0) { for (i = 0; i < NUMPIXELS; i++) { if (random(0, 100) > 60) { ring.setPixelColor(i, ring.Color(LED_BRIGHTNESS, (uint8_t)LED_BRIGHTNESS / 5 * 3, 0)); } } } // fadeout the colored LEDs for (i = 0; i < NUMPIXELS; i++) { ledColor = ring.getPixelColor(i); r = (uint8_t)(ledColor >> 16); g = (uint8_t)(ledColor >> 8); if (r > 0) { r -= max(3, (uint8_t)LED_BRIGHTNESS / 5); r = max(0, r); } if (g > 0) { g -= max(3, (uint8_t)LED_BRIGHTNESS / 5); g = max(0, g); } ring.setPixelColor(i, ring.Color(r, g, 0)); } ring.show(); delay(DEMO_DELAY); } } //void pendulum() { byte generation = 5; int i = 0, h = (int)NUMPIXELS / 2; uint32_t ledColor = ring.Color(LED_BRIGHTNESS, (uint8_t)LED_BRIGHTNESS / 5 * 3, 0); do { for (i = 0; i < h; i++) { ring.setPixelColor(i, ledColor); ring.show(); delay(getSpeed(i)); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } for (i = h - 1; i >= 0; i--) { ring.setPixelColor(i, ledColor); ring.show(); delay(getSpeed(i)); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } for (i = NUMPIXELS - 1; i > h; i--) { ring.setPixelColor(i, ledColor); ring.show(); delay(getSpeed(NUMPIXELS - i)); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } for (i = h + 1; i < NUMPIXELS; i++) { ring.setPixelColor(i, ledColor); ring.show(); delay(getSpeed(NUMPIXELS - i)); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } generation--; } while (generation > 0); } int getSpeed(int i) { return (int)(DEMO_DELAY / 3) + 5 * i * i; } //void alternateLeds() { for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4 - 1; colorIndex++) { for (byte mod = 2; mod <= 6; mod++) { for (byte generation = 0; generation < 6; generation++) { for (byte i = 0; i < NUMPIXELS; i++) { if (i % mod == generation % mod) { ring.setPixelColor(i, ledBaseColors[colorIndex]); } else { ring.setPixelColor(i, ring.Color(0, 0, 0)); } } ring.show(); delay(DEMO_DELAY); } } } resetRing(); } //void alternatingColors() { for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4 - 1; colorIndex++) { for (byte generation = 0; generation < 5; generation++) { for (byte i = 0; i < NUMPIXELS; i++) { if (i % 2 == generation % 2) { ring.setPixelColor(i, ledBaseColors[colorIndex]); } else { ring.setPixelColor(i, ledBaseColors[colorIndex + 1]); } } ring.show(); delay(DEMO_DELAY * 3); } } } //void rainbow() { uint8_t r, g, b; for (float offset = 0.0; offset < PI * 5; offset += 0.4) { r = (uint8_t)((sin(offset * 1.0) + 1) / 2 * LED_BRIGHTNESS); g = (uint8_t)((sin(offset * 1.5) + 1) / 2 * LED_BRIGHTNESS); b = (uint8_t)((sin(offset * 2.0) + 1) / 2 * LED_BRIGHTNESS); for (byte i = 0; i < NUMPIXELS; i++) { ring.setPixelColor(i, ring.Color(r, g, b)); } ring.show(); delay(DEMO_DELAY); } } //void randomColors() { uint8_t r, g, b; for (byte generation = 0; generation < 75; generation++) { for (byte i = 0; i < NUMPIXELS; i++) { r = random(0, LED_BRIGHTNESS); g = random(0, LED_BRIGHTNESS); b = random(0, LED_BRIGHTNESS); ring.setPixelColor(i, ring.Color(r, g, b)); } ring.show(); delay(DEMO_DELAY); } } //void flash() { for (byte generation = 0; generation < 35; generation++) { resetRing(); delay(DEMO_DELAY); for (byte i = 0; i < NUMPIXELS; i++) { uint32_t ledColor = ring.Color(LED_BRIGHTNESS, LED_BRIGHTNESS, LED_BRIGHTNESS); ring.setPixelColor(i, ledColor); } ring.show(); delay(10); } } //void randomFlashes() { for (byte generation = 0; generation < 75; generation++) { resetRing(); delay(DEMO_DELAY); for (byte i = 0; i < NUMPIXELS; i++) { if (random(0, 100) > 90) { ring.setPixelColor(i, ring.Color(LED_BRIGHTNESS, LED_BRIGHTNESS, LED_BRIGHTNESS)); } } ring.show(); delay(10); } } //void colorWipe() { for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4; colorIndex++) { for (byte i = 0; i < NUMPIXELS; i++) { ring.setPixelColor(i, ledBaseColors[colorIndex]); ring.show(); delay(DEMO_DELAY); } } } //void pairCircling() { for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4 - 1; colorIndex++) { for (byte i = 0; i < NUMPIXELS; i++) { ring.setPixelColor(i, ledBaseColors[colorIndex]); ring.setPixelColor(NUMPIXELS - i, ledBaseColors[colorIndex + 1]); ring.show(); delay(DEMO_DELAY); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.setPixelColor(NUMPIXELS - i, ring.Color(0, 0, 0)); ring.show(); } } } //void tailCircling() { uint32_t color; uint8_t r, g, b; byte tailLength = 5; for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4; colorIndex++) { for (byte i = 0; i < NUMPIXELS; i++) { for (byte i = 0; i < NUMPIXELS; i++) { color = ring.getPixelColor(i); r = (uint8_t)(color >> 16); g = (uint8_t)(color >> 8); b = (uint8_t)color; if (r > 0) { r -= max(3, (uint8_t)LED_BRIGHTNESS / tailLength); r = max(0, r); } if (g > 0) { g -= max(3, (uint8_t)LED_BRIGHTNESS / tailLength); g = max(0, g); } if (b > 0) { b -= max(3, (uint8_t)LED_BRIGHTNESS / tailLength); b = max(0, b); } ring.setPixelColor(i, ring.Color(r, g, b)); } ring.setPixelColor(i, ledBaseColors[colorIndex]); ring.show(); delay(DEMO_DELAY); } } } //void simpleCircling() { for (byte colorIndex = 0; colorIndex < sizeof(ledBaseColors) / 4; colorIndex++) { for (byte i = 0; i < NUMPIXELS; i++) { ring.setPixelColor(i, ledBaseColors[colorIndex]); ring.show(); delay(DEMO_DELAY); ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } } } //void resetRing() { for (byte i = 0; i < NUMPIXELS; i++) { ring.setPixelColor(i, ring.Color(0, 0, 0)); ring.show(); } // Read the value of the temp/humidity sensor on A0 // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) h = dht.readHumidity(); t = dht.readTemperature(); //t = (t*1.8)+32; //C to F conversion String tempVal = doubleToString(t, 2); String humVal = doubleToString(h, 0); // String sensorVal = String(1.234); // convert the reading to a char array tempVal.toCharArray(tempPrintout, 6); humVal.toCharArray(humPrintout, 6); // set the font color TFTscreen.stroke(255,255,255); // print the sensor value TFTscreen.text(tempPrintout, 0, 25); TFTscreen.text(humPrintout, 0, 75); // wait for a moment delay(cycleTime); // erase the text you just wrote TFTscreen.stroke(0,0,0); TFTscreen.text(tempPrintout, 0, 25); TFTscreen.text(humPrintout, 0, 85); } //Rounds down (via intermediary integer conversion truncation) String doubleToString(double input,int decimalPlaces){ if(decimalPlaces!=0){ String string = String((int)(input*pow(10,decimalPlaces))); if(abs(input)<1){ if(input>0) string = "0"+string; else if(input<0) string = string.substring(0,1)+"0"+string.substring(1); } return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces); } else { return String((int)input); } }