Hey I'm new to the whole Arduino family and I'm trying to do a very simple project
1: have a push button to start the program
2: have the program stop once it done.
( from what i learned it's in a constant Loop)
3: have the program run a 20% duty cycle for 5sec, then 50% duty cycle for 5 sec and end with a 85% duty cycle for 5sec on one output.
4: have another button that i can press which would allow me to control the duty cycle with a potentiometer.
I have no problem getting it to start with a push button and to do the duty cycle, what I can't figure out is how to get the duty cycle to run for the five seconds, then switch to the next duty cycle and then stop
I suggest you set an integer variable, let's call it STEP, and set it's value initially to 0
When you press the start button have the program increment it to a 1 (stage 1)
Then have the first part of the program test for 'if STEP = 1 then (your first actions)
At the end of step 1 actions have the program increment STEP to value 2.
Clearly it will now ignore the STEP = 1 section of the code, and move on to the code which satisfies 'if STEP = 2'.
...and so on
At the end of the last step (you decide how many) make STEP = 0 again, and the program will wait for the pushbutton to be pressed before starting again.
As for the potentiometer modification, I'm sure better minds than mine will be along soon.
I can't help with the specific code as I'm a novice too!
Alexpaine:
I have no problem getting it to start with a push button and to do the duty cycle, what I can't figure out is how to get the duty cycle to run for the five seconds, then switch to the next duty cycle and then stop
You need to post your program so we can see what you have been trying.
#define LED 9 #define KNOB 0
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 4; // second pushbutton
const int ledPin = 9; // for testing purpose will switch to relay later
int buttonState = 0;
void loop() {
buttonState = digitalRead(buttonPin1);
if (buttonState == HIGH) {
analogWrite(9, 64);
//need 5 sec run time
analogWrite(9, 127);
//need 5 sec run time
analogWrite(9, 215);
// need 5 sec run time
for(;;){} // i think this will prevent the loop from restarting?????
}
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {
// Read the value of the potentiometer knob
int knobValue = analogRead(KNOB);
// Map the potentiometer value to 1-255
int intensity = map(knobValue, 1, 1024, 1, 255);
// Output the respective value to the LED
analogWrite(LED, intensity);
}
}
What i would like it to do is "flash" the led for 5 Seconds at a certain flash rate pause flash LED for 5 seconds at a different pulse rate pause Flash the LED for 5 seconds at a different pulse rate and then stop flashing the LED all together and not repeat the loop
Im so lost... I have spent the last two hours reading and rereading all about delay millis, I've even tried watching YouTube videos and everything
I understand the concept behind the idea just not how to apply it.
Alexpaine:
I am learning very quickly that this is not as easy for me as I had thought..
I think sometimes people get stuck because they fail to realize a computer is utterly stupid - which means that a program must describe every little thing at a level of detail which would never be necessary with another human.
Robin2:
I think sometimes people get stuck because they fail to realize a computer is utterly stupid
LOL so true. I recall a question not so long ago which was something like "why doesn't it switch off the LED after I release the button? I only tell it to switch on the LED when the button is pressed, so it should go off when not!"
Answer: "you never told the Arduino to switch off the LED, only to switch it on".
Indeed, you have to spell out everything for a computer, explicitly. They only do what you tell them to do, nothing more and nothing less.
The concept for this assignment is indeed a quite straightforward finite state machine. The trigger for cycling through the states is time (using the millis() timer); every state is doing something specific with your LED.
Robin2:
I think sometimes people get stuck because they fail to realize a computer is utterly stupid - which means that a program must describe every little thing at a level of detail which would never be necessary with another human.
...R
You're very right I do know that computers are stupid and I feel just about as dumb as they are I'm putting my nose to the grindstone and going to see if I can find someone to help me
Such requests would normally go to the "gigs & collaborations" section, and have a price tag attached. Though not likely you'll find someone willing to do your school assignments for you.
wvmarle:
Such requests would normally go to the "gigs & collaborations" section, and have a price tag attached. Though not likely you'll find someone willing to do your school assignments for you.
I kind of wish it was a school project because then I would have a teacher to show me how to do this
I'll put an ad in the gig section to see if I can find somebody thank you for the info.