Hello,
I am new to the Arduino world. I started with the blink example since I will need a few of these in my project and noticed that the reset toggles PIN 13 three times before initializing the example code. This may exist on all PINs but I do not have an oscilloscope to verify, besides many members most likely know this answer already. I searched "reset causes PIN 13 to toggle" and was absolutely floored to find only one thread that resulted from that search ((Solved! ..Software Solution) How to prevent Output pins floating on boot - General Electronics - Arduino Forum). I was not very satisfied or at least very confused by "saturation" and exactly what the solution was but I gathered that using pull down resistors for the digital PINs will avoid this. This also happens during power up as well.
I observe:
3 fairly quick pulses followed by a 1 second OFF state followed by a short duration HIGH state. The program then continues as expected.
I assume:
The code started after the third quick pulse. This would mean that the first high pulse was too short as described in the code. I changed the statement "int ledState = LOW" in the code to init the PIN to HIGH and was surprised to see that the only change was a longer LOW state after the last short pulse. I have no idea how I can tell when the code actually starts based on the above experiment. I thought that maybe the timer started during the initialization before the code initialization. Best guess so far.
Why is PIN 13 toggling?
This PIN is being driven, this is not floating voltage so I have no idea how a pull up resistor will change this PIN's state during the Reset function. If I had an oscilloscope I expect to see a square wave during the reset which is why the LED is on long enough to see and does not have any dimming whatsoever. Floating voltage I would expect to see a shark-tooth wave but only one pulse and fast enough that the LED would not be visible. Floating voltage does not sustain current. I do not mind being wrong so please correct me if I am.
Is PIN 13 useful to me (I never want to see a PIN changing state without the code directing it to)?
Using ARDUINO UNO genuine from italy and the example code is:
/* Blink without Delay
Turns on and off a light emitting diode (LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
- LED attached from pin 13 to ground.
- Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald
This example code is in the public domain.
*/
// constants won't change. Used here to set a pin number :
const int ledPin = 13; // the number of the LED pin
// Variables will change :
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change :
const long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
If you feel inclined to help then thank you in advance,
Chris