Hi, I want the program to read serial data and change code based on it. And save it. I need it to change the timing. This line
theBlinker.setPeriod(5000);
I need help again.
This is the code of the intervalometer. I will make a c# program
Thank You JIM LEE!
#include <mechButton.h> // Silver bullet 1 deals with a button.
#include <blinker.h> // Silver bullet 2 deals with the LED/Output pin.
#define OUTPUT_PIN 3
#define BUTTON_PIN 4 // The pin nunber for the button.
#define BUTTON_PRESSED LOW // If its backwards make this HIGH.
#define LED_1 5
#define LED_2 6
#define LED_3 7
#define LED_4 8
#define LED_5 9
blinker theBlinker(OUTPUT_PIN,50,5000); // An object that toggles an output pin.
mechButton theButton(BUTTON_PIN); // An object that manages a button on an input pin. Debounce, all them things.
bool buttonState; // Holder for the state of our button.
int mode; // Holder for the state of our output.
// Standard setup.
void setup() {
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
pinMode(LED_4, OUTPUT);
pinMode(LED_5, OUTPUT);
theBlinker.setOnOff(false); // This initial call will initialse the pin and set the LED off.
mode = 0; // We start at LED off. (Mode 0)
buttonState = theButton.trueFalse(); // Read and note initial button state.
}
// We have seen the button change states. Lets deal with it.
void buttonChange(void) {
if (theButton.trueFalse()==BUTTON_PRESSED) { // If the button is in the pressed state..
switch(mode) { // Looking at mode, we want to chage to..
case 0 :
theBlinker.setPeriod(5000); // Setting the blinker 5 seconds.
theBlinker.setOnOff(true); // Fire up the blinker.
mode = 5; // We are now in mode 5.
digitalWrite(LED_1, HIGH);
break; // And we're done.
case 5 : // We are running 5 sec wait, want 10.
theBlinker.setPeriod(10000); // Setting the blinker 10 seconds.
mode = 10; // We are now in mode 10.
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, HIGH);
break; // Done, bolt!
case 10 : // We are running 10 sec wait, want 20.
theBlinker.setPeriod(20000); // Setting the blinker 20 seconds.
mode = 20; // We are now in mode 20.
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(LED_3, HIGH);
break; // Our work is done here.
case 20 : // We are running 20 sec wait, want 30.
theBlinker.setPeriod(30000); // Setting the blinker 30 seconds.
mode = 30; // We are now in mode 30.
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(LED_3, LOW);
digitalWrite(LED_4, HIGH);
break;
case 30 : // We are running 30 sec wait, want 60.
theBlinker.setPeriod(60000); // Setting the blinker 60 seconds.
mode = 60; // We are now in mode 60.
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(LED_3, LOW);
digitalWrite(LED_4, LOW);
digitalWrite(LED_5, HIGH);
break;
case 60 : // We are running 30 sec wait, we want it off.
theBlinker.setOnOff(false); // Easy, just shut the thing off.
mode = 0; // And we are in mode 0;
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(LED_3, LOW);
digitalWrite(LED_4, LOW);
digitalWrite(LED_5, LOW);
break;
}
}
}
//Our loop..
void loop() {
idle(); // Runs the things that like to run in the background.
if (buttonState!=theButton.trueFalse()) { // If the button has changed state..
buttonChange(); // We call the state changing function.
buttonState = !buttonState; // And we flip the button state.
}
}