Advertisement
rossoreed

Triac control software

May 2nd, 2012
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. char c;
  2. unsigned long current_time;
  3. unsigned long start_time = 0;
  4. unsigned long burst_start;
  5. int triac = 13;
  6. int cycle_legnth = 1000; //the legnth of each burst cycle
  7. int burst_legnth; //the time that the triac is switched on
  8.  
  9. void setup() {
  10.  pinMode(triac, OUTPUT);
  11.  Serial.begin(115200);
  12. }
  13. void loop() {
  14.  current_time = millis();
  15. //Reading input from keyboard 0-9
  16. if (Serial.available())
  17. {
  18.   c = Serial.read();
  19. }
  20. int n = c - '0';
  21.  
  22. burst_legnth = (((n)*(cycle_legnth))/10);
  23.  
  24. //Timing functions
  25. if ((current_time) >= (start_time + cycle_legnth)) {
  26. start_time = current_time;
  27. burst_start = current_time;
  28. Serial.println (n);
  29. Serial.print("Triac on at ");
  30. Serial.println (current_time);
  31. digitalWrite(triac,HIGH);
  32. }
  33. else if ((current_time) >= (burst_start + burst_legnth)) {
  34. digitalWrite(triac,LOW);
  35. Serial.println(burst_legnth);
  36. Serial.print("Triac off at ");
  37. Serial.println (current_time);
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement