Advertisement
RuiViana

Untitled

Apr 22nd, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. int LAMP = 3;
  2. int dimming = 1;
  3. int i = 0;
  4.  
  5. String str;
  6.  
  7. void setup()
  8. {
  9. Serial.begin(9600);
  10. delay(300);
  11.  
  12. pinMode(LAMP, OUTPUT);
  13.  
  14. attachInterrupt(0, zero_crosss_int, RISING);
  15. }
  16.  
  17. void loop()
  18. {
  19. Serial.println(dimming);
  20. if(Serial.available() > 0)
  21. {
  22. str = Serial.readStringUntil('\n');
  23. dimming = str.toInt();
  24. Serial.println(dimming);
  25. }
  26. delay(100);
  27. }
  28.  
  29. void zero_crosss_int()
  30. {
  31. int dimtime = (65 * dimming);
  32. delayMicroseconds(dimtime);
  33. digitalWrite(LAMP, HIGH);
  34. delayMicroseconds(8.33);
  35. digitalWrite(LAMP, LOW);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement