Blink example seems to not follow the code


hello,

i new arduino world. started blink example since need few of these in project , noticed reset toggles pin 13 3 times before initializing example code. may exist on pins not have oscilloscope verify, besides many members know answer already. searched "reset causes pin 13 toggle" , absolutely floored find 1 thread resulted search (https://forum.arduino.cc/index.php?topic=216544.0). not satisfied or @ least confused "saturation" , solution gathered using pull down resistors digital pins avoid this. happens during power well.

i observe:
3 quick pulses followed 1 second off state followed short duration high state. program continues expected.

i assume:
the code started after third quick pulse. mean first high pulse short described in code. changed statement "int ledstate = low" in code init pin high , surprised see change longer low state after last short pulse. have no idea how can tell when code starts based on above experiment. thought maybe timer started during initialization before code initialization. best guess far.

why pin 13 toggling?
this pin being driven, not floating voltage have no idea how pull resistor change pin's state during reset function. if had oscilloscope expect see square wave during reset why led on long enough see , not have dimming whatsoever. floating voltage expect see shark-tooth wave 1 pulse , fast enough led not visible. floating voltage not sustain current. not mind being wrong please correct me if am.

is pin 13 useful me (i never want see pin changing state without code directing to)?


using arduino uno genuine italy , example code is:

/* blink without delay

 turns on , off light emitting diode (led) connected digital
 pin, without using delay() function.  means other code
 can run @ same time without being interrupted led code.

 the circuit:
 * led attached pin 13 ground.
 * note: on arduinos, there led on board
 that's attached pin 13, no hardware needed example.

 created 2005
 by david a. mellis
 modified 8 feb 2010
 by paul stoffregen
 modified 11 nov 2013
 by scott fitzgerald


 this example code in public domain.

 http://www.arduino.cc/en/tutorial/blinkwithoutdelay
 */

// constants won't change. used here set pin number :
const int ledpin =  13;      // number of led pin

// variables change :
int ledstate = low;             // ledstate used set led

// generally, should use "unsigned long" variables hold time
// value become large int store
unsigned long previousmillis = 0;        // store last time led updated

// constants won't change :
const long interval = 1000;           // interval @ blink (milliseconds)

void setup() {
  // set digital pin output:
  pinmode(ledpin, output);
}

void loop() {
  // here you'd put code needs running time.

  // check see if it's time blink led; is, if the
  // difference between current time , last time blinked
  // led bigger interval @ want to
  // blink led.
  unsigned long currentmillis = millis();

  if (currentmillis - previousmillis >= interval) {
    // save last time blinked led
    previousmillis = currentmillis;

    // if led off turn on , vice-versa:
    if (ledstate == low) {
      ledstate = high;
    } else {
      ledstate = low;
    }

    // set led ledstate of variable:
    digitalwrite(ledpin, ledstate);
  }
}

if feel inclined thank in advance,
chris

please use code tags (</> button on toolbar) when post code or warning/error messages. reason forum software can interpret parts of code markup, leading confusion, wasted time, , reduced chance problem. make easier read code , copy ide or editor. if browser doesn't show posting toolbar can manually add code tags:
[code]// code here[/code]
using code tags , other important information explained in how use forum post. please read it.

the bootloader code runs every time press reset button or power arduino board on toggles pin 13. doesn't affect other pins.


Arduino Forum > Using Arduino > Programming Questions > Blink example seems to not follow the code


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???