Hi, I'm super new doing this, so sorry if this is a dumb question. I've been playing around with the basics of an Arduino Uno. However, I can't find anything that says how to run programs once I've uploaded them to the Arduino. I've tried this multiple times, and have troubleshooted to the best of my ability, but with no success. Is there a button to run it somewhere in IDE?
the code is automatically run after uploaded.
EDIT: have a part in your code that tells the arduino to run a function when you press a button hooked up to it. This function could be any code that you want run.
Thank you! That makes sense. Where can I find example codes that can do that?
This is a demo-code that makes the onboard LED blink and prints
"Hello World" once every second to the serial monitor
As you are very new to programming. You can save a lot of trouble by learning
NOT
to use delay() for timing.
using delay() will cause you a lot of trouble because you are learning to think
the wrong way.
You will be ahead of 98% of all newcomers if you learn thinking
most-outer-circular repeating
instead of
inner-loop-linear-top-down
right from the start.
This is what this code shows
unsigned long MyTestTimer = 0; // Timer-variables MUST be of type unsigned long
const byte OnBoard_LED = 13; // onboard-LED On Arduino Uno is IO-pin 13
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
}
void loop() {
BlinkHeartBeatLED(OnBoard_LED,250);
if ( TimePeriodIsOver(MyTestTimer,1000) ) {
Serial.println("Hello World");
}
}
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
static unsigned long MyBlinkTimer;
pinMode(IO_Pin, OUTPUT);
if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
digitalWrite(IO_Pin,!digitalRead(IO_Pin) );
}
}
You simply compile / upload this code and the LED should start blinking
and you will see
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
in the serial monitor
adjust your serial monitor to 115200 baud
best regards Stefan
Hello criesinmychemicalromance
Just try the BlinkWithoutDelay example of the IDE to get started.
This BlinkWithoutDelay example is harder to understand for the following reasons:
- very short comments
- the comments do not explicitly point out that non-blocking timing works
fundamentally different than blocking timing - variables are distributed across the code
- the names of the variables are not intuitive
This example-code seems to be set in stone. Though a lot of things could be improved.
For me it has something Pharisee-like
Make science difficult so that not everyone understands it
This program waits for the button to start the rest of the program.
Hi,
Given that you’re entirely ‘super new’ to Arduino, I would start with something ‘super simple’. Such as:
- Lighting an LED when a button is depressed.
- Ditto, but as soon as it’s pressed the LED stays on for say 5 seconds.
- As 1 and 2 but with two buttons and the LED lights if either of them is pressed.
- Then move onto blinking, with simple delays.
- Ditto but without delays, as described up-thread.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.