Умные головы помогите пожалуйста разобраться куда копать?
- Войдите на сайт для отправки комментариев
Ср, 25/05/2016 - 11:45
сделал led табло под небольшие часы на диодах ws2812b с размером одной цифры 3*5 диоды спаяны в следующем порядке 5 6 13 18 19 26 32 33 40 45 46 53 4 12 17 25 31 39 44 52 3 7 11 16 20 24 27 30 34 38 43 47 51 2 10 15 23 29 37 42 50 1 8 9 14 21 22 28 35 36 41 48 49 попытался переделать скетч под такие цифры в виде:
byte digits[10][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,1,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,0,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
в оригинальном скетче на цифру было использовано больше диодов (21 диод), но при опросе в мониторе СОМ порта выдает цыфры как были прописаны до изменения тоесть 13моих символов+8 не понятно от куда взятых. К примеру Digit 4 is : 1110111110111******** = 2, соответственно на табло вместо времени черти что. Куда копать? Вот измененный мною скетч
#include <DS3232RTC.h> #include <Time.h> #include <Wire.h> #include <FastLED.h> #define NUM_LEDS 53 // 5 by segment + 6 in the middle #define LED_TYPE WS2812 #define COLOR_ORDER GRB // Define color order for your strip #define BRIGHTNESS 150 #define LED_PIN 5 // Data pin for led comunication CRGB leds[NUM_LEDS]; // Define LEDs strip byte digits[10][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,1,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,0,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 | 2D Array for numbers on 7 segment byte firstdigit[2][5] = { {0,0,0,0,0}, // Digit 0 first number {1,1,1,1,1}}; // Digit 1 first number | 2D Array for numbers on 7 segment 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::MediumVioletRed; long ColorTable[16] = { CRGB::Amethyst, CRGB::Aqua, CRGB::Blue, CRGB::Chartreuse, CRGB::DarkGreen, CRGB::DarkMagenta, CRGB::DarkOrange, CRGB::DeepPink, CRGB::Fuchsia, CRGB::Gold, CRGB::GreenYellow, CRGB::LightCoral, CRGB::Tomato, CRGB::Salmon, CRGB::Red, CRGB::Orchid}; void setup(){ Serial.begin(9600); Wire.begin(); FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS); //FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); //pinMode(6, INPUT_PULLUP); // Define DST adjust button pin pinMode(4, INPUT_PULLUP); // Define Minutes adjust button pin pinMode(2, INPUT_PULLUP); // Define Hours adjust button pin } // Check Light sensor and set brightness accordingly void BrightnessCheck(){ const byte sensorPin = 3; // light sensor pin const byte brightnessLow = 75; // Low brightness value const byte brightnessHigh = 100; // High brightness value int sensorValue = digitalRead(sensorPin); // Read sensor if (sensorValue == 0) { Serial.println("Brightness High"); LEDS.setBrightness(brightnessHigh); } else { Serial.println("Brightness Low"); LEDS.setBrightness(brightnessLow); } }; // Get time in a single number 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); }; 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); }; } // Convert time to array needet for display void TimeToArray(){ int Now = GetTime(); // Get time int cursor = 53; //116 Serial.print("Time is: "); Serial.println(Now); if (Dot){ leds[25]=ledColor; leds[26]=ledColor; leds[27]=ledColor; leds[28]=ledColor; leds[29]=ledColor; //leds[48]=ledColor; } else { leds[25]=0x000000; leds[26]=0x000000; leds[27]=0x000000; leds[28]=0x000000; leds[29]=0x000000; //leds[48]=0x000000; }; for(int i=1;i<=4;i++){ int digit = Now % 10; // get last digit in time if (i==1){ cursor =40; //82 Serial.print("Digit 4 is : "); Serial.print(digit); Serial.print(", the array is : "); for(int k=0; k<=20;k++){ Serial.print(digits[digit][k]); if (digits[digit][k]== 1){ leds[cursor]=ledColor; } else if (digits[digit][k]==0){ leds[cursor]=0x000000; }; cursor ++; }; // fin for Serial.println(); if (digit != last_digit) { fadefonction(); ledColor = ColorTable[random(16)]; } last_digit = digit; }// fin if else if (i==2){ cursor =27; Serial.print("Digit 3 is : "); Serial.print(digit); Serial.print(", the array is : "); for(int k=0; k<=20;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){ cursor =13; Serial.print("Digit 2 is : "); Serial.print(digit); Serial.print(", the array is : "); for(int k=0; k<=20;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){ cursor =0; Serial.print("Digit 1 is : "); Serial.print(digit); Serial.print(", the array is : "); for(int k=0; k<=20;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 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; if (buttonH == LOW){ if (Now.Hour== 24){ Now.Hour=1; } 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 { /*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 float t = RTC.temperature(); float celsius = t / 4.0; Serial.println(); Serial.print("Temp is : "); Serial.print(celsius); Serial.println(); }
порядок диодов ниже
5 6 13 18 19 26 32 33 40 45 46 53 4 12 17 25 31 39 44 52 3 7 11 16 20 24 27 30 34 38 43 47 51 2 10 15 23 29 37 42 50 1 8 9 14 21 22 28 35 36 41 48 49
Скетч плохо читается, потому что нет отступов.
Предполагаю, что 21 символ берутся из-за следующих строчек:
for(int k=0; k<=20;k++)
Спасибо с этим уже разобрался да действительно в for(int k=0; k<=20;k++) вместо 20 для моих часов должно быть 12 и еще не учел той вещи что первый диод это 0,а не 1. А я счет с единицы начинал =)