Created
April 18, 2016 17:19
-
-
Save dwblair/e1daeef0c2edf949c755d513ea5e4197 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <TimerOne.h> | |
| // This example uses the timer interrupt to blink an LED | |
| // and also demonstrates how to share a variable between | |
| // the interrupt and the main program. | |
| const int led = 3; // the pin with a LED | |
| int ledState = LOW; | |
| // note: need to add amplification factor | |
| void setup(void) | |
| { | |
| pinMode(led, OUTPUT); | |
| Timer1.initialize(500); | |
| Timer1.attachInterrupt(blinkLED); // blinkLED to run every 0.15 seconds | |
| Serial.begin(9600); | |
| pinMode(10, OUTPUT); // powers the subcircuit | |
| digitalWrite(10,HIGH); | |
| } | |
| // The interrupt will blink the LED, and keep | |
| // track of how many times it has blinked. | |
| volatile int flag = 0; //whether we're in the 'on' state | |
| void blinkLED(void) | |
| { | |
| if (ledState == LOW) { | |
| ledState = HIGH; | |
| flag = 1; | |
| //blinkCount = blinkCount + 1; // increase when LED turns on | |
| } else { | |
| ledState = LOW; | |
| } | |
| digitalWrite(led, ledState); | |
| } | |
| // The main program will print the blink count | |
| // to the Arduino Serial Monitor | |
| void loop(void) | |
| { | |
| /* | |
| noInterrupts(); | |
| flag = 0; // write to the flag without conflicting with ISR writes | |
| interrupts(); | |
| */ | |
| // read A0 | |
| int val1 = analogRead(0); | |
| // read A1 | |
| // int val2 = analogRead(1); | |
| int val2 = 0; // just have dummy variable for now | |
| // print to serial | |
| Serial.print(val1); | |
| Serial.print(" "); | |
| Serial.print(val2); | |
| Serial.print("\n"); | |
| // wait | |
| delay(50); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment