Помогите вывести температуру на часы
- Войдите на сайт для отправки комментариев
Пт, 03/06/2016 - 06:54
Сделал часы на ленте WS2812b, время показывают, цвета меняют, все как надо. Цыфра из 13 додов 5*3. RTC у меня DS3231 в нем есть термометр, хочу с него выводить температуру на часы ну к примеру каждую минуту, продолжительностью 5 секунд в виде 26°C (первые две цыфры температура без десятых или сотых, вторые две цыфры ° и C ) в скетче прописал опрос датчика в мониторе порта есть температура, как мне теперь это безобразие вывести на табло с нужными мне интервалами времени? Сильно не пинайте ардуинку только осваиваю =) Вот мой скетч того что на данный момент есть.
#include <DS3231RTC.h> #include <Time.h> #include <Wire.h> #include "FastLED.h" #define NUM_LEDS 54 // Number of LED controles (remember I have 3 leds / controler #define COLOR_ORDER BRG // Define color order for your strip #define DATA_PIN 6 // Data pin for led comunication #define DS3232_I2C_ADDRESS 0x68 CRGB leds[NUM_LEDS]; // Define LEDs strip byte digits[12][13] = { {1,1,1,1,1,1,0,1,1,1,1,1,1}, // Digit 0 {0,0,0,0,0,0,0,0,1,1,1,1,1}, // Digit 1 {1,1,1,0,1,1,1,1,1,0,1,1,1}, // Digit 2 {1,0,1,0,1,1,1,1,1,1,1,1,1}, // Digit 3 {0,0,1,1,1,0,1,0,1,1,1,1,1}, // Digit 4 {1,0,1,1,1,1,1,1,1,1,1,0,1}, // Digit 5 {1,1,1,1,1,1,1,1,1,1,1,0,1}, // Digit 6 {0,0,0,0,1,1,0,0,1,1,1,1,1}, // Digit 7 {1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 8 {1,0,1,1,1,1,1,1,1,1,1,1,1}, // Digit 9 {0,0,1,1,1,1,1,0,0,0,1,1,1}, // Digit ° {1,1,1,1,1,1,0,1,1,0,0,0,1}}; // Digit C bool Dot = true; //Dot state bool DST = false; //DST state int last_digit = 0;//long ledColor = CRGB::DarkOrchid; // Color used (in hex) long ledColor = CRGB::Lime; long ColorTable[16] = { CRGB::Orange, CRGB::Aqua, CRGB::Gold, CRGB::Red, CRGB::Yellow, CRGB::Cyan, CRGB::Orange, CRGB::Lime, CRGB::Pink, CRGB::Red, CRGB::Orange, CRGB::Tomato, CRGB::Aqua, CRGB::Orange, CRGB::Lime, CRGB::Yellow}; void setup(){ Serial.begin(9600); Wire.begin(); LEDS.addLeds<WS2812, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Set LED strip type LEDS.setBrightness(255); // Set initial brightness pinMode(2, INPUT_PULLUP); // Define DST adjust button pin pinMode(4, INPUT_PULLUP); // Define Minutes adjust button pin pinMode(5, INPUT_PULLUP); // Define Hours adjust button pin } // Get time in a single number, if hours will be a single digit then time will be displayed 155 instead of 0155 int GetTime(){ tmElements_t Now; RTC.read(Now); //time_t Now = RTC.Now();// Getting the current Time and storing it into a DateTime object int hour=Now.Hour; int minutes=Now.Minute; int second =Now.Second; if (second % 2==0) {Dot = false;} else {Dot = true;}; return (hour*100+minutes); }; // Check Light sensor and set brightness accordingly void BrightnessCheck(){ const byte sensorPin = 3; // light sensor pin const byte brightnessLow = 30; // Low brightness value const byte brightnessHigh = 220; // High brightness value int sensorValue = digitalRead(sensorPin); // Read sensor if (sensorValue == 0) {LEDS.setBrightness(brightnessHigh);} else {LEDS.setBrightness(brightnessLow);} }; // Convert time to array needet for display void TimeToArray(){ int Now = GetTime(); // Get time int cursor = 54; // Serial.print("Time is: ");Serial.println(Now); if (DST){ // if DST is true then add one hour Now+=100; // Serial.print("DST is ON, time set to : ");Serial.println(Now); }; if (Dot){leds[26]=ledColor; leds[27]=ledColor;} else {leds[26]=0x000000; leds[27]=0x000000; }; for(int i=1;i<=4;i++){ int digit = Now % 10; // get last digit in time if (i==1){ // Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" "); cursor =41; for(int k=0; k<=12;k++){ // Serial.print(digits[digit][k]); if (digits[digit][k]== 1){leds[cursor]=ledColor;} else if (digits[digit][k]==0){leds[cursor]=0x000000;}; cursor ++; }; Serial.println(); if (digit != last_digit) { fadefonction(); ledColor = ColorTable[random(16)]; } last_digit = digit; }// fin if else if (i==2){ // Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" "); cursor =28; for(int k=0; k<=12;k++){ // Serial.print(digits[digit][k]); if (digits[digit][k]== 1){leds[cursor]=ledColor;} else if (digits[digit][k]==0){leds[cursor]=0x000000;}; cursor ++; }; // Serial.println(); } else if (i==3){ // Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" "); cursor =13; for(int k=0; k<=12;k++){ // Serial.print(digits[digit][k]); if (digits[digit][k]== 1){leds[cursor]=ledColor;} else if (digits[digit][k]==0){leds[cursor]=0x000000;}; cursor ++; }; // Serial.println(); } else if (i==4){ // Serial.print("Digit1 is : ");Serial.print(digit);Serial.print(" "); cursor =0; for(int k=0; k<=12;k++){ // Serial.print(digits[digit][k]); if (digits[digit][k]== 1){leds[cursor]=ledColor;} else if (digits[digit][k]==0){leds[cursor]=0x000000;}; cursor ++; }; // Serial.println(); } Now /= 10; }; }; void DSTcheck(){ int buttonDST = digitalRead(2); // Serial.print("DST is: ");Serial.println(DST); if (buttonDST == LOW){ if (DST){ DST=false; // Serial.print("Switching DST to: ");Serial.println(DST); } else if (!DST){ DST=true; // Serial.print("Switching DST to: ");Serial.println(DST); }; delay(500); }; } void TimeAdjust(){ int buttonH = digitalRead(5); int buttonM = digitalRead(4); if (buttonH == LOW || buttonM == LOW){ delay(500); tmElements_t Now; RTC.read(Now); int hour=Now.Hour; int minutes=Now.Minute; int second =Now.Second; if (buttonH == LOW){ if (Now.Hour== 23){Now.Hour=0;} else {Now.Hour += 1;}; }else { if (Now.Minute== 59){Now.Minute=0;} else {Now.Minute += 1;}; }; RTC.write(Now); } } void fadeall() { for(int m = 0; m < NUM_LEDS; m++) { leds[m].nscale8(250); } } void fadefonction () { static uint8_t hue = 0; // First slide the led in one direction for(int i = 0; i < NUM_LEDS; i++) { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds FastLED.show(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; fadeall(); // Wait a little bit before we loop around and do it again delay(10); } // Now go in the other direction. for(int i = (NUM_LEDS)-1; i >= 0; i--) { // Set the i'th led to red leds[i] = CHSV(hue++, 255, 255); // Show the leds FastLED.show(); // now that we've shown the leds, reset the i'th led to black // leds[i] = CRGB::Black; fadeall(); // Wait a little bit before we loop around and do it again delay(10); } } void loop() // Main loop { byte tempMSB, tempLSB, temp; float temperature; Wire.beginTransmission(DS3232_I2C_ADDRESS); Wire.write(0x11); // move register pointer to first temperature register Wire.endTransmission(); Wire.requestFrom(DS3232_I2C_ADDRESS, 2); tempMSB = Wire.read(); tempLSB = Wire.read() >> 6; temperature = tempMSB + (0.25*tempLSB); Serial.print(" Temperature (C): "); Serial.println(temperature); delay(10); BrightnessCheck(); // Check brightness DSTcheck(); // Check DST TimeAdjust(); // Check to se if time is geting modified TimeToArray(); // Get leds array with required configuration FastLED.show(); // Display leds array }
Из-за того что вы время сделали челым числом, а не строкой - выводить темпиратуру будет сложно.
Переменную темпиратуры сделайте глобальной. Добавьте переменную Temp также как Dot, переключайте ее раз в 5 секунд.
В выводе TimeToArray - добавьте условие для каждого знака - если нужно выводить темпиратуру то задавайте заного нужный вам digit. В дувх первых его нужно получить из темпиратуры, в двух последних(i==2 и i==1) он равен 10(градус) и 11(буква с).
Вопрос не совсем по теме.
Можно ли вместо:
Записать так:
или так:
Можно даже так
Спасибо!
не могли бы по подробней расписать что куда зачем и почему, с ардуинкой еще не совсем на ты, даже сказал бы пока еще на как вообще )) дело в том что скетч ни я писал, я лишь перекроил его под свое табло и добавил красивую смену цветов, по истечении каждой минуты