Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char c;
- unsigned long current_time;
- unsigned long start_time = 0;
- unsigned long burst_start;
- int triac = 13;
- int cycle_legnth = 1000; //the legnth of each burst cycle
- int burst_legnth; //the time that the triac is switched on
- void setup() {
- pinMode(triac, OUTPUT);
- Serial.begin(115200);
- }
- void loop() {
- current_time = millis();
- //Reading input from keyboard 0-9
- if (Serial.available())
- {
- c = Serial.read();
- }
- int n = c - '0';
- burst_legnth = (((n)*(cycle_legnth))/10);
- //Timing functions
- if ((current_time) >= (start_time + cycle_legnth)) {
- start_time = current_time;
- burst_start = current_time;
- Serial.println (n);
- Serial.print("Triac on at ");
- Serial.println (current_time);
- digitalWrite(triac,HIGH);
- }
- else if ((current_time) >= (burst_start + burst_legnth)) {
- digitalWrite(triac,LOW);
- Serial.println(burst_legnth);
- Serial.print("Triac off at ");
- Serial.println (current_time);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement