Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3. volatile int count=0;
  4. long debounce_time=0;
  5. long debounce=300;
  6. double freq=1;
  7. static const int LED_PIN=13;
  8. static const int digital_pin=2;
  9. bool previousButtonState=HIGH;
  10. void interrupt_handle(){
  11. if(millis()-debounce_time>debounce){
  12. freq=freq+freq*1/10;
  13. delay(20);
  14. Serial.print(freq);
  15. delay(20);
  16. Serial.println();
  17. }
  18. debounce_time=0;
  19. }
  20. void led_miganie(int freq){
  21. digitalWrite(LED_PIN,HIGH);
  22. delay(60/freq);
  23. digitalWrite(LED_PIN,LOW);
  24. delay(60/freq);
  25.  
  26. }
  27. void setup() {
  28. // put your setup code here, to run once:
  29. Serial.begin(9600);
  30. lcd.begin(16, 2);
  31. lcd.print("waiting...");
  32. pinMode(digital_pin,INPUT);
  33. pinMode(LED_PIN,OUTPUT);
  34. //attachInterrupt(digitalPinToInterrupt(digital_pin), interrupt_handle, FALLING);
  35. }
  36.  
  37. void loop() {
  38. // put your main code here, to run repeatedly:
  39. bool currentButtonState=digitalRead(digital_pin);
  40. if((currentButtonState==LOW)&&(previousButtonState==HIGH)){
  41. interrupt_handle();
  42. }
  43. if(Serial.available()>0){
  44. freq=1;
  45. Serial.read();
  46. Serial.print(freq);
  47. delay(20);
  48. Serial.println();
  49. }
  50. previousButtonState=currentButtonState;
  51. led_miganie(freq);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement