Tuesday, May 25, 2010

Some for-loop examples

//(1) Print 0 1 2 ...9 to serial screen
for(int i = 0; i <10; i =" 100;" i =" 0;" i =" 0;" style="font-weight:bold;">i=i+2) {
Serial.println(i);
}

//(5) Print 0 1 2 ...999. You don't have to use i as a variable.
for(int longUselessVariable = 0; longUselessVariable <10000 ;longUselessVariable++ ) {
Serial.println(longUselessVariable );
}

//(6) The for loop can repeat any code between the { and the }
//Output 10 blinks then go to the next piece of code
for(int i = 0; i <10 ;i++) {
digitalWrite(ledPin, HIGH); // set the LED on
delay(100); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
//next piece of code goes here

Test coming up

There will be a test on Thursday 4 May. This will take the place of the normal Thursday VC. The test will be on paper and an hour will be allocated for you to do it. It is a closed book test and no extra materials can be brought into class. At the end of the test, hand your answers back to your teacher who will get them back to me for marking.

There will be a question on the parts of the Arduino. Another part of the test will ask you to find the programming language mistakes in a buggy program. You will be asked to write a program that makes a LED blink in a simple way. There will also be questions about for-loops, random numbers and how to send outputs to the serial screen. There will also be a problem to solve involving testing some inputs and outputs on the Arduino. There may be some other questions. We will be going over much of the material the week before.

Tuesday, May 18, 2010

Random numbers on the serial screen.

//Generating random numbers on the serial screen.

long randNumber;

void setup(){
Serial.begin(9600);

randomSeed(analogRead(0)); //shuffles the random numbers
}

void loop() {
// print a random number from 0 to 299
randNumber = random(300);
Serial.println(randNumber);

// print a random number from 10 to 19
randNumber = random(10, 20);
Serial.println(randNumber);

delay(50);
}

Your friend, the reference screen



The reference screen in the Arduino help section is your best friend when programming.



Click to make the picture bigger. The reference screen in the Arduino help section is your best friend when programming.


Monday, May 17, 2010

Freeduino information


Freeduino site has lots of information about Arduino projects