Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial Komunikace(12,13);
  3. unsigned char play[6] = {0x7E,0x04,0x03,0x00,0x01,0xEF};
  4. unsigned char SC_SD[5] = {0x7E,0x03,0x09,0x01,0xEF};
  5. unsigned char play_mode[5] = {0x7E,0x03,0x11,0x00,0xEF};
  6. unsigned char PredchoziPisnicka[4] = {0x7E,0x02,0x02,0xEF};
  7. unsigned char DalsiPisnicka[4] = {0x7E, 0x02, 0x01, 0xEF};
  8. unsigned char HlasitostPlus[4] = {0x7E,0x02,0x04,0xEF};
  9. unsigned char HlasitostMinus[4] = {0x7E,0x02,0x05,0xEF};
  10. int adc_key_val[5] ={20,50, 100, 200, 600 };
  11. int NUM_KEYS = 5;
  12. int adc_key_in;
  13. int key=-1;
  14. int oldkey=-1;
  15. void setup()
  16. {
  17. Serial.begin(9600);
  18. Komunikace.begin(9600);
  19. Komunikace.write(SC_SD,5);
  20. }
  21. void loop()
  22. {
  23. adc_key_in = analogRead(0); // read the value from the sensor
  24. key = get_key(adc_key_in); // convert into key press
  25.  
  26. if (key != oldkey) // if keypress is detected
  27. {
  28. delay(50); // wait for debounce time
  29. adc_key_in = analogRead(0); // read the value from the sensor
  30. key = get_key(adc_key_in); // convert into key press
  31. if (key != oldkey)
  32. {
  33. oldkey = key;
  34. if (key >=0){
  35. switch(key)
  36. {
  37. case 0:Komunikace.write(play,6);
  38. break;
  39. case 1:
  40. for(int i = 0; i < 10; i++){
  41. Komunikace.write(HlasitostPlus, 4);
  42. }
  43. break;
  44. case 2:
  45. for(int i = 0; i < 10; i++){
  46. Komunikace.write(HlasitostMinus, 4);
  47. }
  48. break;
  49. case 3:Komunikace.write(PredchoziPisnicka, 4);
  50. break;
  51. case 4:Komunikace.write(DalsiPisnicka, 4);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. delay(100);
  58. }
  59. // Convert ADC value to key number
  60. int get_key(unsigned int input)
  61. {
  62. int k;
  63. for (k = 0; k < NUM_KEYS; k++)
  64. {
  65. if (input < adc_key_val[k])
  66. {
  67. return k;
  68. }
  69. }
  70. if (k >= NUM_KEYS)k = -1; // No valid key pressed
  71. return k;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement