Baby steps...
To begin, i used the arduino examples and looked at using a potentiometer (analog input) to control an output; led. i set up this circuit.
This was a good example to follow. I needed to see the values of the potentiometer so i used a code from my real time clock and inserted it into the example;
Serial.begin(9600); //read value from sensor
void loop ()
Serial.pintin(name you have given); //show value in your COM
I could now turn the potentiometer and see the values change in relation to my blinking LED.
I then opened my real time clock file and started making adjustments, doing a 'save as' so not to muck up my original code.
baby step 2...
I opened another arduino example of using 'if else'. This code allows you to set an action to a variable, like my time.
My goal: to set a time for a red led to turn on, otherwise keep green led on.
if(minute == 1) { // == must be used to use an exact value! otherwise will not work!
digitalWrite(redPin, HIGH); //turn on red pin
digitalWrite(greenPin, LOW); //turn off green pin
}
else { //otherwise turn green led on
digitalWrite(redPin, LOW); //turn off red pin
digitalWrite(greenPin, HIGH); //turn on green pin
}
This was good but would not let me keep more than one minute on.
Baby step 3...
I removed my 'if, else' with 'case' again using an arduino example.
First thing i needed to do with my real time clock programme, was to define my constants for the red led to be on;
const int nameMin = value; // mine was minuteMin = 1: this sets the min value for red led to be on
const int minuteMax = 2; //sets max value for red led to be on.
in the 'void loop' section of the code, i added;
int range = map(minute, minuteMin, minuteMax, 0,2) //maps sensor range to four options.
switch (range) { //do something different depending on the range value.
case 0: //action when 1 min is reached
digitalWrite(redPin, HIGH); //turn on red pin
digitalWrite(greenPin, LOW); //turn off green pin
serial.print("sleep");
break;
this allowed my leds to react to a duration i set.
I had completed my goal of controlling an output based on my time.
void loop ()
Serial.pintin(name you have given); //show value in your COM
I could now turn the potentiometer and see the values change in relation to my blinking LED.
I then opened my real time clock file and started making adjustments, doing a 'save as' so not to muck up my original code.
baby step 2...
I opened another arduino example of using 'if else'. This code allows you to set an action to a variable, like my time.
My goal: to set a time for a red led to turn on, otherwise keep green led on.
if(minute == 1) { // == must be used to use an exact value! otherwise will not work!
digitalWrite(redPin, HIGH); //turn on red pin
digitalWrite(greenPin, LOW); //turn off green pin
}
else { //otherwise turn green led on
digitalWrite(redPin, LOW); //turn off red pin
digitalWrite(greenPin, HIGH); //turn on green pin
}
This was good but would not let me keep more than one minute on.
Baby step 3...
I removed my 'if, else' with 'case' again using an arduino example.
First thing i needed to do with my real time clock programme, was to define my constants for the red led to be on;
const int nameMin = value; // mine was minuteMin = 1: this sets the min value for red led to be on
const int minuteMax = 2; //sets max value for red led to be on.
in the 'void loop' section of the code, i added;
int range = map(minute, minuteMin, minuteMax, 0,2) //maps sensor range to four options.
switch (range) { //do something different depending on the range value.
case 0: //action when 1 min is reached
digitalWrite(redPin, HIGH); //turn on red pin
digitalWrite(greenPin, LOW); //turn off green pin
serial.print("sleep");
break;
this allowed my leds to react to a duration i set.
I had completed my goal of controlling an output based on my time.
No comments:
Post a Comment