Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial Komunikace(12,13);
- unsigned char play[6] = {0x7E,0x04,0x03,0x00,0x01,0xEF};
- unsigned char SC_SD[5] = {0x7E,0x03,0x09,0x01,0xEF};
- unsigned char play_mode[5] = {0x7E,0x03,0x11,0x00,0xEF};
- unsigned char PredchoziPisnicka[4] = {0x7E,0x02,0x02,0xEF};
- unsigned char DalsiPisnicka[4] = {0x7E, 0x02, 0x01, 0xEF};
- unsigned char HlasitostPlus[4] = {0x7E,0x02,0x04,0xEF};
- unsigned char HlasitostMinus[4] = {0x7E,0x02,0x05,0xEF};
- int adc_key_val[5] ={20,50, 100, 200, 600 };
- int NUM_KEYS = 5;
- int adc_key_in;
- int key=-1;
- int oldkey=-1;
- void setup()
- {
- Serial.begin(9600);
- Komunikace.begin(9600);
- Komunikace.write(SC_SD,5);
- }
- void loop()
- {
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey) // if keypress is detected
- {
- delay(50); // wait for debounce time
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey)
- {
- oldkey = key;
- if (key >=0){
- switch(key)
- {
- case 0:Komunikace.write(play,6);
- break;
- case 1:
- for(int i = 0; i < 10; i++){
- Komunikace.write(HlasitostPlus, 4);
- }
- break;
- case 2:
- for(int i = 0; i < 10; i++){
- Komunikace.write(HlasitostMinus, 4);
- }
- break;
- case 3:Komunikace.write(PredchoziPisnicka, 4);
- break;
- case 4:Komunikace.write(DalsiPisnicka, 4);
- break;
- }
- }
- }
- }
- delay(100);
- }
- // Convert ADC value to key number
- int get_key(unsigned int input)
- {
- int k;
- for (k = 0; k < NUM_KEYS; k++)
- {
- if (input < adc_key_val[k])
- {
- return k;
- }
- }
- if (k >= NUM_KEYS)k = -1; // No valid key pressed
- return k;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement