noob for now....

Easy questions, I’m frankly a little embarrassed to be asking:

My last ‘serious’ programming was many hours of basic on a commodore VIC-20 so I may be a touch rusty… :oops:

  1. Running a loop for repetitive tasks.

For some reason I can’t simply figure out how to use a ‘for-loop’ to complete a repetitive task. As simple as possible: how do I write a loop to, let’s say, blink the LED 5 times in a row without simply writing the on-off sequence 5 times? I should be able to write a for loop and then include the on-off seq in the {} following the loop line, but it doesn’t seem to take.

( I’m working on an automatic cat feeder but the LED demo will answer the question!) :slight_smile:

  1. IF-AND-ELSE condition.

Again as simple as possible, If I write a program that one button turns on LED1, and the second button lights LED2 (no problem solving this…), how do I structure the program to turn on LED3 if BOTH buttons are pressed?

  1. (which you may want to answer instead of the previous 2!)…

Bought The Sparkfun inventors kit this week and am having a blast with it! Have sold at least another 4 boards in the few days since to other friends and family who are intrigued by what we can cook up. Turns out these are a great tool to unleash the inner inventor/mad scientist!

However… none of us have any experience in programming in ‘C’. Can anyone point me in the direction of a good book or resource to take a virtual beginner to the next level? (meaning fewer questions of the caliber I have just posted!) The kit projects are a ton of fun, but I’d really like to depart off the path and start to see more original ideas realized, and progress along the way.

Thanks a ton!

This is a good on-line C book.

http://publications.gbdirect.co.uk/c_book/

The standard book on C is K&R:

http://www.amazon.com/Programming-Langu … 0131103628

For #1:

int i;
for( i=0; i<5; i++) {
    LED = ON;
    delay(x);
    LED = OFF;
    delay(x);
}

Where delay(x) is a function and x is the delay value.

For #2:

if (button1 == 1) {
     LED1 = ON;
}
if (button2 == 1) {
     LED2 = ON;
}
if ((button1 == 1) && (button2 == 1)) {
   LED3 = ON;
}

This would turn on all three LEDs if both button are pressed.

If you don’t want LED1 or LED2 lit when both buttons are press then:

if ((button1 == 1) && (button2 == 0)) {
     LED1 = ON;
} 
 if ((button2 == 1) && (button1 == 0)) {
     LED2 = ON;
}
if ((button1 == 1) && (button2 == 1)) {
   LED3 = ON;
}

With a 1 == a pressed button (note this may == 0 if button is a port pin and the port is pulled high with a resistor and the pressed button grounds the port pin).

These are just a couple of ways to code your examples.

Thanks a bunch. Looks like I had the elements, just not arranged properly…

Took the guidance on the books as well. Found an excellent one called:

‘Beginning Arduino’ by Michael McRoberts.

It tackles a bunch of projects (from blinking LED to an RFID access system) and details every line of code to explain what’s happening, as well as technical descriptions of how the parts ( LEDs, shift registers, ultrasonic sensors, etc.) operate.

Greatly appreciated!