#include <Wire.h> #include <LiquidCrystal.h> #include <Conceptinetics.h> #define DMX_SLAVE_CHANNELS 512 #define LCD_W 16 // ( ) LiquidCrystal lcd(12, 11, 5, 4, 3, 2); DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS ); unsigned long lastFrameReceivedTime = 0; // unsigned long lastFrameTranceivedTime = 0; // byte qa[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111 }; byte ws[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111 }; byte ed[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }; byte rf[8] = { B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111 }; byte tg[8] = { B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111 }; byte yh[8] = { B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111 }; byte uj[8] = { B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte ik[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; byte outAr [LCD_W]; // , unsigned short chRx; // #define KEY_BUTTON_1_PIN A2 // unsigned int KeyButton1Value=0; // unsigned long KeyButton1TimePress=0; // unsigned long KeyButton1Latency=100; // unsigned int KeyButton1WasChecked=0; // unsigned long KeyButton1RepeatLatency=1500; // unsigned long KeyButton1RepeatTimePress=0; // unsigned long KeyButton1TimeFromPress=0; // unsigned long KeyBoardTime1=0; // unsigned long KeyBoardTime2=0; // unsigned long KeyBoardTimeInterval=25; // byte start = 0; // +1 , void setup() { lcd.begin(LCD_W, 2); dmx_slave.enable (); dmx_slave.setStartAddress (1); dmx_slave.onReceiveComplete ( OnFrameReceiveComplete ); lcd.createChar(0,qa); lcd.createChar(1,ws); lcd.createChar(2,ed); lcd.createChar(3,rf); lcd.createChar(4,tg); lcd.createChar(5,yh); lcd.createChar(6,uj); lcd.createChar(7,ik); pinMode (KEY_BUTTON_1_PIN, INPUT); pinMode (10, OUTPUT); pinMode (9, OUTPUT); digitalWrite(9, LOW); } void loop() { // KeyBoardTime2=millis(); if ((KeyBoardTime2-KeyBoardTime1)>KeyBoardTimeInterval) { KeyBoardTime1=KeyBoardTime2; KeyBoardCalculate(); } if (lastFrameReceivedTime > lastFrameTranceivedTime){ // printLevel (outAr); // lastFrameTranceivedTime = millis(); } else if ((lastFrameReceivedTime==0 && lastFrameTranceivedTime ==0)||(KeyBoardTime2-lastFrameReceivedTime>2000)) { lcd.clear(); delay (500); lcd.setCursor(0, 0); lcd.print("NO SIGNAL"); delay (500); } } void OnFrameReceiveComplete (unsigned short channelsReceived) // , { chRx = channelsReceived; // , for (byte i=0; i<LCD_W; i++){ // outAr[i]=dmx_slave.getChannelValue (i+start+1); } lastFrameReceivedTime = millis(); } void printLevel(byte lv[LCD_W]) // { byte dispLv[LCD_W]; for (byte i=0; i<LCD_W; i++){ switch (lv[i]/32) { //// case 0: dispLv[i]=0; break; case 1: dispLv[i]=1; break; case 2: dispLv[i]=2; break; case 3: dispLv[i]=3; break; case 4: dispLv[i]=4; break; case 5: dispLv[i]=5; break; case 6: dispLv[i]=6; break; case 7: dispLv[i]=7; break; } } lcd.setCursor(0, 0); for (byte i=0; i<LCD_W; i++){ // lcd.write(dispLv[i]); // } // lcd.setCursor(0, 1); lcd.print("^"); // if ((start+1)<10) { // lcd.print((start+1)); // lcd.print(" "); // } else if ((start+1)<100 && (start+1)>9) { // lcd.print((start+1)); // lcd.print(" "); // } else lcd.print((start+1)); // lcd.setCursor(5, 1); lcd.print("V:"); // if (lv[0]<10) { // lcd.print("00"); // lcd.print(lv[0]); // } else if (lv[0]<100 && lv[0]>9) { // lcd.print("0"); // lcd.print(lv[0]); // } else lcd.print(lv[0]); // lcd.setCursor(11, 1); lcd.print("T:"); // lcd.print(chRx); // } void ButtonPress() // , { if ((KeyButton1Value>200) and (KeyButton1Value<500)) { if((start) < (chRx-LCD_W) && chRx>LCD_W) start++; // } if ((KeyButton1Value>500) and (KeyButton1Value<1000)) { if(start > 0) start--; // } } void KeyBoardCalculate() { // KeyButton1Value=analogRead(KEY_BUTTON_1_PIN); // if ((KeyButton1Value<=50) or (KeyButton1Value>=1000)) { // KeyButton1TimePress=millis(); KeyButton1WasChecked=0; KeyButton1RepeatTimePress=0; } KeyButton1TimeFromPress=millis()-KeyButton1TimePress; // if ((KeyButton1Value>50) and (KeyButton1Value<1000)) { // if ( ((KeyButton1TimeFromPress)>KeyButton1Latency) and (KeyButton1WasChecked==0)) { KeyButton1Value=analogRead(KEY_BUTTON_1_PIN); ButtonPress(); KeyButton1WasChecked=1; KeyButton1RepeatTimePress=0; } // if ( ((KeyButton1TimeFromPress)>(KeyButton1RepeatLatency+KeyButton1RepeatTimePress)) and (KeyButton1WasChecked==1)) { KeyButton1Value=analogRead(KEY_BUTTON_1_PIN); ButtonPress(); KeyButton1RepeatTimePress=KeyButton1RepeatTimePress+100; } } }
Source: https://habr.com/ru/post/357888/
All Articles