📜 ⬆️ ⬇️

Arduino in the car. Instrument dubbing

The talking device is designed for those who do not notice the light bulbs on the instrument panel, and periodically catches itself that goes with the handbrake or the main beam. Or that the speedometer imperceptibly crawled forward much… Yeah, I did it for myself.

It was checked for (sharpened) Daewoo Nexia N150, but it should work on any machine with an electronic speedometer (speed sensor - 6 pulses per meter, sort of like a standard). Photos a bit muddy (amateur):

image

image
')
Functional:
1. Speaks in voice (5 volume levels) about various events (events are described below)

a) male
b) female

Voices are synthesized on a computer, recorded as a set of mp3 files on a micro SD card. This means that you can change or record them.

2. Settings are performed with the remote control from the TV (or any other with a sufficient number of buttons, I highly recommend the remote control with the buttons 0-9). Settings are remembered at the moment of change.

3. In case of failure / loss of the remote control, the detector can be quickly switched to the “no sound” or “no sound except handbrake” modes. For this, a triple switching on of dimensions is used (the idea of ​​using the flashing dimensions as a control signal for adjusting the tap from some kind of DRL brightness adjustment device).

Sound events (disableable)
- Handbrake (if the parking brake light is on while driving)
- The high beam is on (the far flash is ignored, warns once after switching on, does not remind further, until the far one switches)
- Turn on the running lights (if the movement is started without the dimensions included, my DRL and the near one do not work for me if the dimensions are not included).
- Voltage on-board network (accuracy up to a tenth of a volt)
- Exceeding the speed threshold of 40, 50, ... 120, 130 km / h.
- Lowering the speed threshold of 40, 50, ... 120, 130 km / h.
- Changing the volume, switching the voice, turning off / on each of the events being voiced (switching on the voltmeter simultaneously causes voltage to sound).

Video with demonstration:



Connect to auto
1. To the speedometer - just three wires: ground, +12 (from here we take power to the device and data for a voltmeter), a signal from the speed sensor.

2. For light bulbs - parking brake, high beam, instrument lighting (dimensions).

The matching of the levels is made quite simple - the arduine outputs are pulled up by the internal resistor at “1”, and the 12V level signals from the dashboard go through the diodes. When the panel goes +12, the diode is closed - on the Arduine "log.1". When the signal from the panel goes to ground - the diode is open, the internal pull-up resistor is ignored, at the Arduino output "log.0".

A voltmeter is simply a resistive divider to an analog input. The ratio is approximately 1:13, from the calculation that at the maximum on-board network voltage of 16V (emergency mode), the ADC will reach its limit with a reference signal of 1.2V.

The composition of the device
1. Arduino nano v3

Ali reference

2. MP3 Module - DFplayer mini

Ali reference

This module in the Internet diagrams is connected via tx / rx signals, I added the analysis of the busy signal, in order to catch the moment of the end of the sound playback, so that the new notification would not interrupt the current one, but stand in a queue.

3. Amplifier PAM8403 (optional)

Ali reference

4. Development board, 5 resistors (2 per ADC voltmeter, and 3 per DFplayer pins), 4 diodes (matching with + 12V), as well as a pair of capacitors and a +7 V power supply stabilizer chip (LMSR805) 7805, because it was in stock and does not heat up), piezummer (squeaks when mp3 files queue overflows, more for debugging errors), connectors for connecting an IR sensor (jack 2.5 in my case, but this is unprincipled) and dynamics ( I took RCA), well, and the connector for the instrument panel (I took the IDC10, with snaps on the dad - quite light and multi-contact)

Firmware:
From the firmware text, you can easily see where all of the analyzed signals are located, where to put the codes of your IR remote control (you can take them using the IRRecvDump demo sketch). Also, the constants clearly spell out the response times of voice speeds (note that the speeds are sounded a little earlier than they are actually achieved - in order to have time to slow down without exceeding).

#include <Wire.h> //#include <LiquidCrystal_I2C.h> #include <IRremote.h> #include <EEPROM.h> #include <SoftwareSerial.h> #include <DFPlayer_Mini_Mp3.h> int RECV_PIN = 6; //  IR  IRrecv irrecv(RECV_PIN); decode_results results; byte cfg[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; byte mp3stek[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte mp3stekpos = 0; volatile byte busy = 1; //mp3 busy 0=play volatile byte softbusy = 0; volatile byte nomer_mp3 = 1; volatile unsigned long micros_sp = 0; volatile byte sz = 0; //  volatile unsigned int sp = 0; // volatile unsigned int sp20 = 0; //*10 volatile boolean st = false; // volatile byte ruka = 1; // volatile byte dsvet = 0; //. volatile byte gaba = 0; // volatile byte lastspeed = 0; //  volatile byte lastdsvet = 0; //   . volatile byte lastgaba = 0; //   DHO volatile byte lastgabaonoff = 0; //     volatile word gabaonofftimer = 0; //      volatile byte gabaonoffcounter = 0; //      volatile byte speed40 = 38; // 40 volatile byte speed60 = 58; // 60 volatile byte speed80 = 78; // 80 volatile byte speed110 = 108; // 110 volatile byte unspeed40 = 36; // no 40 volatile byte unspeed60 = 56; // no 60 volatile byte unspeed80 = 76; // no 80 volatile byte unspeed110 = 106; // no 110 volatile byte speed50 = 48; // 50 volatile byte unspeed50 = 46; // no 50 volatile byte speed70 = 68; // 70 volatile byte unspeed70 = 66; // no 70 volatile byte speed90 = 88; // 90 volatile byte unspeed90 = 86; // no 90 volatile byte speed100 = 98; // 100 volatile byte unspeed100 = 96; // no 100 volatile byte speed120 = 118; // 120 volatile byte unspeed120 = 116; // no 120 volatile byte speed130 = 128; // 130 volatile byte unspeed130 = 126; // no 130 volatile byte s40 = 0; volatile byte s50 = 0; volatile byte s60 = 0; volatile byte s70 = 0; volatile byte s80 = 0; volatile byte s90 = 0; volatile byte s100 = 0; volatile byte s110 = 0; volatile byte s120 = 0; volatile byte s130 = 0; //LiquidCrystal_I2C lcd(0x3F, 16, 2); float sensorValue = 0; //V float outputValue = 0; //V void setup() { Serial.begin(9600); Serial.println("start programm NEXIA 1.0"); //start IR reciver irrecv.enableIRIn(); // Start the receiver // initialize the LCD //lcd.begin(); // Turn on the blacklight and print a message. //lcd.backlight(); // lcd.print("Hello, world!"); //tone (17,3000); //    D3 pinMode(2, INPUT); //      speed digitalWrite(2, HIGH);//   pinMode(3, INPUT); //      digitalWrite(3, HIGH);//   pinMode(4, INPUT); //      digitalWrite(4, HIGH);//   pinMode(5, INPUT); //      digitalWrite(5, HIGH);//   // pinMode(13, OUTPUT); // lastgabaonoff = digitalRead(5); //gaba attachInterrupt(0,speedometr, RISING); cfg[0]=EEPROM.read(5); //0=all sound 1=no sound(ruka) 2=no sound all cfg[1]=EEPROM.read(6); //volume mp3 0..30 cfg[2]=EEPROM.read(7); //0 = dsvet sound? 1 = no dsvet sound cfg[3]=EEPROM.read(8); //0 = 40sound cfg[4]=EEPROM.read(9); //0 = 60sound cfg[5]=EEPROM.read(10);//0 = 80sound cfg[6]=EEPROM.read(11);//0 = 110 sound cfg[7]=EEPROM.read(12);//0 = Voltmetr sound cfg[8]=EEPROM.read(13);//0 = DHO sound cfg[9]=EEPROM.read(14);//0 = 50sound cfg[10]=EEPROM.read(15);//0 = 70sound cfg[11]=EEPROM.read(16);//0 = 90sound cfg[12]=EEPROM.read(17);//0 = 100sound cfg[13]=EEPROM.read(18);//0 = 120sound cfg[14]=EEPROM.read(19);//0 = 130sound cfg[15]=EEPROM.read(20);//0 = 0, 1=1 // 3 pinMode(7, INPUT); //busy mp3_set_serial (Serial); // mp3_set_volume (25); mp3setvol(); delay (100); add_mp3(32); //   //  analogReference (INTERNAL); // voltmeter(); if (cfg[7]==0){voltmetertest();} //  } void loop() { //   dsvet = digitalRead(3); //    : // if (dsvet==1) { lcd.setCursor(3, 0); lcd.print("DD ");} // else{lcd.setCursor(3, 0); lcd.print("_s ");}; ruka = digitalRead(4); //    : // if (ruka==1) { lcd.setCursor(0, 0); lcd.print("_r ");} // else{lcd.setCursor(0, 0); lcd.print("RR ");}; gaba = digitalRead(5); //    : // if (gaba==1) { lcd.setCursor(6, 0); lcd.print("GG");} // else{lcd.setCursor(6, 0); lcd.print("_g");}; //voltmetertest(); //  // digitalWrite(13, !digitalRead(2)); //  // lcd.setCursor(10, 0); // lcd.print(" "); // lcd.setCursor(10, 0); // lcd.print(sp); // lcd.setCursor(0, 1); // lcd.print(" "); // lcd.setCursor(0, 1); // lcd.print(sp20); if (sz != 0){sz--;}else{sp20=0;sp=0;}; delay(50); // sdisplay(); // gabamute(); //      if ((sp20>0)&(ruka==0)) {rukabeep();}//  else { // .        if (dsvet==1) { if ( lastdsvet<200){lastdsvet=lastdsvet+1;};} if (dsvet==1) { if ((lastdsvet>35)&(lastdsvet<38)){svetbeep();}; } if (dsvet==0) {lastdsvet=0;}; //  .  //   if ((gaba==0)&&(sp20>0)) { if ( lastgaba<150){lastgaba=lastgaba+1;};} if ((gaba==0)&&(sp20>0)) { if ((lastgaba>20)&(lastgaba<23)){DHO_beep();}; } if (gaba==1) {lastgaba=0;}; if (sp20==0) {lastgaba=0;}; //    40, 60, 80, 110 if ((lastspeed<speed40)&(sp>=speed40)) { if (s40<1) { svet1beep(); s40=1; }}; if ((lastspeed>=unspeed40)&(sp<unspeed40)) { if (s40>0) { nsvet1beep(); s40=0; }}; if ((lastspeed<speed50)&(sp>=speed50)) { if (s50<1) { svet50beep(); s50=1; }}; if ((lastspeed>=unspeed50)&(sp<unspeed50)) { if (s50>0) { nsvet50beep(); s50=0; }}; if ((lastspeed<speed60)&(sp>=speed60)) { if (s60<1) { svet2beep(); s60=1; }}; if ((lastspeed>=unspeed60)&(sp<unspeed60)) { if (s60>0) { nsvet2beep(); s60=0; }}; if ((lastspeed<speed70)&(sp>=speed70)) { if (s70<1) { svet70beep(); s70=1; }}; if ((lastspeed>=unspeed70)&(sp<unspeed70)) { if (s70>0) { nsvet70beep(); s70=0; }}; //.   66/    " 70" - .     . if ((lastspeed<speed80)&(sp>=speed80)) { if (s80<1) { svet3beep(); s80=1; }}; if ((lastspeed>=unspeed80)&(sp<unspeed80)) { if (s80>0) { nsvet3beep(); s80=0; }}; if ((lastspeed<speed90)&(sp>=speed90)) { if (s90<1) { svet90beep(); s90=1; }}; if ((lastspeed>=unspeed90)&(sp<unspeed90)) { if (s90>0) { nsvet90beep(); s90=0; }}; if ((lastspeed<speed100)&(sp>=speed100)) { if (s100<1) { svet100beep(); s100=1; }}; if ((lastspeed>=unspeed100)&(sp<unspeed100)) { if (s100>0) { nsvet100beep(); s100=0; }}; if ((lastspeed<speed110)&(sp>=speed110)) { if (s110<1) { svet4beep(); s110=1; }}; if ((lastspeed>=unspeed110)&(sp<unspeed110)) { if (s110>0) { nsvet4beep(); s110=0; }}; if ((lastspeed<speed120)&(sp>=speed120)) { if (s120<1) { svet120beep(); s120=1; }}; if ((lastspeed>=unspeed120)&(sp<unspeed120)) { if (s120>0) { nsvet120beep(); s120=0; }}; if ((lastspeed<speed130)&(sp>=speed130)) { if (s130<1) { svet130beep(); s130=1; }}; if ((lastspeed>=unspeed130)&(sp<unspeed130)) { if (s130>0) { nsvet130beep(); s130=0; }}; lastspeed=sp; delay(50); //    }//     // voltmeter(); //  3 if (mp3stekpos != 0) { busy = digitalRead(7); //    7: if (softbusy > 0) softbusy = softbusy-1;// , .. busy    if ((busy>0) && (softbusy ==0)) //   3 {mp3stekpos = mp3stekpos-1; nomer_mp3 = mp3stek[1]; if (cfg[15]==0) {mp3_play (mp3stek[1]);} else {mp3_play (mp3stek[1]+100);} //  softbusy = 25; delay(50); for (int i=1; i < 9; i++){mp3stek[i]=mp3stek[i+1]; } mp3stek[9]= 0; };} //   /**/ if (irrecv.decode(&results)) { Serial.println(results.value); // lcd.setCursor(6, 1); // lcd.print(results.value); //  //       0-2 if ((results.value==2255209021)|| (results.value==2255218711)) { cfg[0]=cfg[0]+1; if (cfg[0]>2) { cfg[0]=0; }; EEPROM.write(5,cfg[0]); if (cfg[0]==0) {add_mp3(5);}; //sound on if (cfg[0]==1) {add_mp3(3);}; //sound off krome ruka if (cfg[0]==2) {add_mp3(4);}; }//sound off all // V+ -   3 if ((results.value==2255188111)||(results.value==2155866645)) { cfg[1]=cfg[1]+1; if (cfg[1]>4) {cfg[1]=4;add_mp3(41);} if (cfg[1]==1) {add_mp3(38);} if (cfg[1]==2) {add_mp3(39);} if (cfg[1]==3) {add_mp3(40);} if (cfg[1]==4) {add_mp3(41);} mp3setvol(); EEPROM.write(6,cfg[1]); } // V- -   3 if ((results.value==2255210551)||(results.value==2155809015)) { if (cfg[1]<1) {add_mp3(37); } else {cfg[1]=cfg[1]-1;} if (cfg[1]==1) {add_mp3(38);} if (cfg[1]==2) {add_mp3(39);} if (cfg[1]==3) {add_mp3(40);} mp3setvol(); EEPROM.write(6,cfg[1]); } if (results.value==2255192191) // sourse -    +100 { if (cfg[15]==0){ cfg[15]=1;} else { cfg[15]=0;} add_mp3(42); EEPROM.write(20,cfg[15]); } if (results.value==2255222791) //  -  . { if (cfg[2]==0) { cfg[2]=1; add_mp3(18);} //no dsvet else { cfg[2]=0; add_mp3(19); }//dsvet on EEPROM.write(7,cfg[2]); } if (results.value==2255220751) // 4 -   40 { if (cfg[3]==0) { cfg[3]=1; add_mp3(36); }//40 off else { cfg[3]=0; add_mp3(35); }//40 on EEPROM.write(8,cfg[3]); } if (results.value==2255200351) // 5 -   50 { if (cfg[9]==0) { cfg[9]=1; add_mp3(65); } //50 off else { cfg[9]=0; add_mp3(66); }//50 on EEPROM.write(14,cfg[9]); } if (results.value==2255184031) // 6 -   60 { if (cfg[4]==0) { cfg[4]=1; add_mp3(12); }//60 off else { cfg[4]=0; add_mp3(13); }//60 on EEPROM.write(9,cfg[4]); } if (results.value==2255171791) // 7 -   70 { if (cfg[10]==0) {cfg[10]=1; add_mp3(45);} //70 off else { cfg[10]=0; add_mp3(46); }//70 on EEPROM.write(15,cfg[10]); } if (results.value==2255204431) // 8 -   80 { if (cfg[5]==0) { cfg[5]=1; add_mp3(14); }//80 off else { cfg[5]=0; add_mp3(15); }//80 on EEPROM.write(10,cfg[5]); } if (results.value==2255179951) // 9 -   90 { if (cfg[11]==0) {cfg[11]=1; add_mp3(49);} //90 off else { cfg[11]=0; add_mp3(50);} //90 on EEPROM.write(16,cfg[11]); } if (results.value==2255194231) // 0 -   100 { if (cfg[12]==0) {cfg[12]=1; add_mp3(53);} //100 off else { cfg[12]=0; add_mp3(54);} //100 on EEPROM.write(17,cfg[12]); } if (results.value==2255167711) // 1 -   110 { if (cfg[6]==0) { cfg[6]=1; add_mp3(16);} //110 off else { cfg[6]=0; add_mp3(17);} //110 on EEPROM.write(11,cfg[6]); } if (results.value==2255163631) // 2 -   120 { if (cfg[13]==0) { cfg[13]=1; add_mp3(57);} //120 off else { cfg[13]=0; add_mp3(58);} //120 on EEPROM.write(18,cfg[13]); } if (results.value==2255175871) // 3 -   130 { if (cfg[14]==0) { cfg[14]=1; add_mp3(61);} //130 off else { cfg[14]=0; add_mp3(62);} //130 on EEPROM.write(19,cfg[14]); } if ((results.value==2255206471)||(results.value==2155829925)) // ? -   { if (cfg[7]==0) { cfg[7]=1; add_mp3(27);} //no  else { cfg[7]=0; add_mp3(28); voltmetertest(); }// on EEPROM.write(12,cfg[7]); } if (results.value==2255190151) //  -  DHO { if (cfg[8]==0) { cfg[8]=1; add_mp3(31);} //no DHO else { cfg[8]=0; add_mp3(30);} //DHO on EEPROM.write(13,cfg[8]); } irrecv.resume(); // Receive the next value } } //      void sdisplay(){ if (ruka==1) { Serial.print("ruka=off ");} else{ Serial.print("RUKA=ON ");}; if (dsvet==1) { Serial.print("dsvet=off ");} else{ Serial.print("DSVET=ON ");}; if (gaba==1) { Serial.print("gaba=off ");} else{ Serial.print("GABA=ON ");}; Serial.println(" "); Serial.print(" speed="); Serial.println(sp); Serial.println("++++++++++++++++++ END ++++++"); } void speedometr(){ if (!st){micros_sp = micros();} else {sp20 = (12000000/(micros() - micros_sp));} sp=sp20/20; st = !st; sz=10;} void rukabeep() { if (cfg[2]!=2) {mp3_play (1);} delay(1000);} void svetbeep() { if ((cfg[2]==0)&&(cfg[0]==0)) {add_mp3(2);}} void DHO_beep() { if ((cfg[8]==0)&&(cfg[0]==0)) {add_mp3(29);}} void svet1beep() { if ((cfg[3]==0)&&(cfg[0]==0)) {add_mp3(33);}} //40 void nsvet1beep() { if ((cfg[3]==0)&&(cfg[0]==0)) {add_mp3(34);}} //n40 void svet50beep() { if ((cfg[9]==0)&&(cfg[0]==0)) {add_mp3(63);}} //50 void nsvet50beep() { if ((cfg[9]==0)&&(cfg[0]==0)) {add_mp3(64);}} //n50 void svet2beep() { if ((cfg[4]==0)&&(cfg[0]==0)) {add_mp3(6);}} //60 void nsvet2beep() { if ((cfg[4]==0)&&(cfg[0]==0)) {add_mp3(7);}} //n60 void svet70beep() { if ((cfg[10]==0)&&(cfg[0]==0)) {add_mp3(43);}} //70 void nsvet70beep() { if ((cfg[10]==0)&&(cfg[0]==0)) {add_mp3(44);}} //n70 void svet3beep() { if ((cfg[5]==0)&&(cfg[0]==0)) {add_mp3(8);}} //80 void nsvet3beep() { if ((cfg[5]==0)&&(cfg[0]==0)) {add_mp3(9);}} //n80 void svet90beep() { if ((cfg[11]==0)&&(cfg[0]==0)) {add_mp3(47);}} //90 void nsvet90beep() { if ((cfg[11]==0)&&(cfg[0]==0)) {add_mp3(48);}} //n90 void svet100beep() { if ((cfg[12]==0)&&(cfg[0]==0)) {add_mp3(51);}} //100 void nsvet100beep(){ if ((cfg[12]==0)&&(cfg[0]==0)) {add_mp3(52);}} //n100 void svet4beep() { if ((cfg[6]==0)&&(cfg[0]==0)) {add_mp3(10);}} //110 void nsvet4beep() { if ((cfg[6]==0)&&(cfg[0]==0)) {add_mp3(11);}} //n110 void svet120beep() { if ((cfg[13]==0)&&(cfg[0]==0)) {add_mp3(55);}} //120 void nsvet120beep(){ if ((cfg[13]==0)&&(cfg[0]==0)) {add_mp3(56);}} //n120 void svet130beep() { if ((cfg[14]==0)&&(cfg[0]==0)) {add_mp3(59);}} //130 void nsvet130beep(){ if ((cfg[14]==0)&&(cfg[0]==0)) {add_mp3(60);}} //n130 //void svet1unbeep(){ tone (17,1000); delay(200); noTone(17);} void add_mp3(byte nomermp3) { if ((mp3stekpos > 8)&&(cfg[0]<2))//     { if (cfg[0]==0) { tone (17,1000); delay(200); tone (17,1400); delay(200); noTone(17); }}//       else { mp3stekpos = mp3stekpos+1; mp3stek[mp3stekpos] = nomermp3; }} //    void mp3setvol() //    0-4  0-30 {if(cfg[1]==0){mp3_set_volume(10);}if(cfg[1]==1){mp3_set_volume(15);}if(cfg[1]==2){mp3_set_volume(20);}if(cfg[1]==3){mp3_set_volume(25);}if(cfg[1]>3){mp3_set_volume(30);}} void voltmetertest() { outputValue = 0; int u_x10 =0 ; int u_x1 =0 ; int u_x0 =0 ; for (int iii=0; iii <10 ; iii++) { outputValue =outputValue + float(analogRead(A0)); delay(100); }//   outputValue = outputValue/620;//     u_x10=round(outputValue*10); // 10 u_x1=floor(u_x10/10); //   add_mp3(70+u_x1); u_x0=u_x10-(10*u_x1); // = 10U-10U add_mp3(90+u_x0); } void gabamute() { if (lastgabaonoff==gaba) {//   gabaonofftimer=gabaonofftimer+1; if (gabaonofftimer>250 ) {//    -   gabaonofftimer=250; gabaonoffcounter=0; } } else {//  lastgabaonoff=gaba; if (gabaonoffcounter==0) {gabaonofftimer=0;} //  // Serial.println(gabaonofftimer); if (gabaonofftimer<25) {//   gabaonoffcounter=gabaonoffcounter+1; gabaonofftimer=0; if (gabaonoffcounter>5) {// -    gabaonoffcounter=0; cfg[0]=cfg[0]+1; if (cfg[0]>2) { cfg[0]=0; }; EEPROM.write(5,cfg[0]); if (cfg[0]==0) {add_mp3(5);}; //sound on if (cfg[0]==1) {add_mp3(3);}; //sound off krome ruka if (cfg[0]==2) {add_mp3(4);}; //sound off all } } else { gabaonoffcounter=0; gabaonofftimer=0; } }} 


Auxiliary Board Firmware
For debugging, debugging and demonstration, another arduin was used - the arduino uno and the LCD display module and buttons.

She knows how to give signals - dimensions, high beam, handbrake, and change the speed from 0 to about 150. Among the shortcomings, there is no suppression of contact bounce, but this moment does not really bother me.

 #include <Wire.h> //    #include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7 ); const int rukaPin = 2; //  =  const int dsvetPin = 1; //  = . const int speedPin = 0; //  =   const int gabaPin = 11; // 6 =  int rukaState = 0; //    int dsvetState = 0; //    int speedState = 0; //    int gabaState = 0; //    int speedkm = 0; // / int lowdelay = 250; //     //   int button; const int BUTTON_NONE = 0; const int BUTTON_RIGHT = 1; const int BUTTON_UP = 2; const int BUTTON_DOWN = 3; const int BUTTON_LEFT = 4; const int BUTTON_SELECT = 5; int getPressedButton() { int buttonValue = analogRead(0); //     (A0) if (buttonValue < 60) { return BUTTON_RIGHT; } else if (buttonValue < 200) { return BUTTON_UP; } else if (buttonValue < 400){ return BUTTON_DOWN; } else if (buttonValue < 600){ return BUTTON_LEFT; } else if (buttonValue < 800){ return BUTTON_SELECT; } return BUTTON_NONE; } void setup() { pinMode(rukaPin, OUTPUT); //     pinMode(dsvetPin, OUTPUT); //     pinMode(speedPin, OUTPUT); //     pinMode(gabaPin, OUTPUT); //     lcd.begin(16, 2); lcd.print("starting..."); delay (500); lcd.clear(); lcd.setCursor(12, 0); if(gabaState == 1){lcd.print("G_ON");}else{lcd.print("GOFF");} digitalWrite(gabaPin,gabaState); lcd.setCursor(6, 0); if(dsvetState == 1){lcd.print("D__ON");}else{lcd.print("D_OFF");} digitalWrite(dsvetPin,dsvetState); lcd.setCursor(0, 0); if(rukaState == 0){lcd.print("R__ON");}else{lcd.print("R_OFF");} digitalWrite(rukaPin,rukaState); } void loop() { delay(50); if ((speedState<=36)&(speedState>0)) { lowdelay=500/speedState; digitalWrite(speedPin,1); delay(lowdelay); digitalWrite(speedPin,0); delay(lowdelay); lcd.setCursor(12, 1); lcd.print(lowdelay); lcd.print(" "); } button = getPressedButton(); switch (button) { case BUTTON_RIGHT: //       lcd.setCursor(12, 0); if (gabaState == 0) { gabaState = 1; lcd.print("G_ON "); } else { gabaState = 0; lcd.print("GOFF "); } digitalWrite(gabaPin,gabaState); break; case BUTTON_LEFT: lcd.setCursor(6, 0); if (dsvetState == 0) { dsvetState = 1; lcd.print("D__ON "); } else { dsvetState = 0; lcd.print("D_OFF "); } digitalWrite(dsvetPin,dsvetState); break; case BUTTON_UP: if (speedState<5){speedState=speedState+1;} else {if (speedState<250){speedState=speedState+5;};} lcd.setCursor(0, 1); lcd.print(speedState); speedkm=speedState*0.6; lcd.print(" "); lcd.print(speedkm); lcd.print("km/h "); if (speedState>35){ tone(speedPin,speedState);} else { noTone(speedPin); }; break; case BUTTON_DOWN: if ((speedState<10)&(speedState>0)){speedState=speedState-1;} else { if ((speedState<255)&(speedState>0)){speedState=speedState-5;} } ; lcd.setCursor(0, 1); lcd.print(speedState); speedkm=speedState*0.6; lcd.print(" "); lcd.print(speedkm); lcd.print("km/h "); // if (speedState==0){noTone(speedPin);} else {tone(speedPin,speedState);}; if (speedState>35){ tone(speedPin,speedState);} else { noTone(speedPin); }; break; case BUTTON_SELECT: // lcd.setCursor(0, 0); // lcd.print(" "); lcd.setCursor(0, 0); if (rukaState == 0) { rukaState = 1; lcd.print("R_OFF "); } else { rukaState = 0; lcd.print("R__ON "); } digitalWrite(rukaPin,rukaState); break; } } 

Source: https://habr.com/ru/post/401671/


All Articles