Created
September 22, 2022 16:53
-
-
Save ricklon/43b4238b609799d3531ad5a1c1615218 to your computer and use it in GitHub Desktop.
TimeOne Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Blink | |
Turns on an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the Uno and | |
Leonardo, it is attached to digital pin 13. If you're unsure what | |
pin the on-board LED is connected to on your Arduino model, check | |
the documentation at http://www.arduino.cc | |
This example code is in the public domain. | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
*/ | |
//#include <TimerOne.h> | |
//#include <Wire.h> | |
#include <MultiFuncShield.h> | |
int time = 250; | |
volatile int loop_count = 0; | |
int done0 = 0; | |
int done1 = 0; | |
int done2 = 0; | |
int done3 = 0; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
Serial.begin(9600); | |
Timer1.initialize(); | |
MFS.initialize(&Timer1); // initialize multi-function shield library | |
pinMode(3, INPUT); | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
pinMode(12, OUTPUT); | |
pinMode(11, OUTPUT); | |
pinMode(10, OUTPUT); | |
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) | |
Timer1.attachInterrupt(timerCallback, 500); | |
Serial.println("Setup Complete"); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
switch (loop_count) { | |
case 0: | |
if (done0 == 0) { | |
done0 = 1; | |
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level) | |
Serial.print(loop_count); | |
} else { | |
done3 = 0; | |
} | |
break; | |
case 1: | |
if (done1 == 0) { | |
done1 = 1; | |
digitalWrite(13, HIGH); // turn the LED off by making the voltage LOW | |
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW | |
Serial.print(loop_count); | |
} else { | |
//done0 = 0; | |
} | |
break; | |
case 2: | |
if (done2 == 0) { | |
done2 = 1; | |
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level) | |
digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level) | |
Serial.print(loop_count); | |
} else { | |
//done1 = 0; | |
} | |
break; | |
case 3: | |
if (done3 == 0) { | |
done3 = 1; | |
digitalWrite(11, HIGH); // turn the LED off by making the voltage LOW | |
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW | |
Serial.print(loop_count); | |
} else { | |
//done2 = 0; | |
done0 = 0; | |
} | |
break; | |
default: | |
Serial.print(loop_count); | |
Serial.println(", Problem with loop"); | |
break; | |
} | |
} | |
void timerCallback() { | |
if (loop_count < 3) { | |
loop_count++; | |
} else { | |
loop_count = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment