Different script to do same thing. Why?


hi there everyone. i'm new on here, , new arduino. i'm working way through basic sketching , trying not ask loads of questions , figure out myself (the spirit of arduino, no?)

but, have question today.
these 2 following bits of code same thing, yet use different syntax.
can explain difference between: '#define' , 'int', when comes setting pin input/output?
i understand int variable, don't understand how used set pins mode. , why both work?

many in advance.
sim

sketch one:

// project 1 - led flasher

int ledpin = 10;

void setup() {
           pinmode(ledpin, output);
}

void loop() {
           digitalwrite(ledpin, high);
           delay(1000);
           digitalwrite(ledpin, low);
           delay(1000);
}


sketch two:


// example 01 : blinking led

#define led 13 // led connected to
// digital pin 13

void setup()
{
 pinmode(led, output);           // sets digital
                                 // pin output
}

void loop()
{
 digitalwrite(led, high);         // turns led on
 delay(1000);                     // waits second
 digitalwrite(led, low);          // turns led off
 delay(1000);                     // waits second
}

the difference using #define, pin number stored in flash memory along sketch.  using int method, variable stored in ram.  for small sketch not important, if start writing large sketches use lot of ram, saving bit of memory might mean difference between success , failure.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Different script to do same thing. Why?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums