Friday, March 19, 2010

programmes

7. Blink: Blinks on for one second and off for one second continuously.

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}


//=================================================================================



8. Quick Blink: Turns on for 10ms and off for one second continuously.

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(10); // wait for 10ms
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}


//=================================================================================



9. Slow Blink: turns on for one second and off for 10ms continuously.

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(10); // wait for 10ms
}


//=================================================================================


10. Rapid Blink: The LED blinks rapidly turning off and on every 10ms.

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(10); // wait for 10ms
digitalWrite(ledPin, LOW); // set the LED off
delay(10); // wait for 10ms
}

My cut off point is three. I think it would differ from person to person seen as some people have better eye sight than others.


//=================================================================================

12. alternate blink



int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
digitalWrite(redLedPin, LOW); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, HIGH); // set the LED off
delay(del); // wait for a second
stop;
}


//=================================================================================


13.mostly on/off

int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 250;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH);// set the LED on
digitalWrite(redLedPin, LOW); // set the LED on
delay(subdel); // wait for a second
digitalWrite(ledPin, LOW);// set the LED on
delay(50);
digitalWrite(ledPin, HIGH);// set the LED on
delay(subdel);
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, HIGH); // set the LED off
delay(del); // wait for a second

}


//=================================================================================


16.blink blink, wink

int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH);// set the LED on
digitalWrite(redLedPin, LOW); // set the LED on
delay(subdel); // wait for a second
digitalWrite(ledPin, LOW);// set the LED on
delay(50);
digitalWrite(ledPin, HIGH);// set the LED on
delay(subdel);
digitalWrite(ledPin, LOW); // set the LED off
delay(subdel); // wait for a second
digitalWrite(redLedPin, HIGH); // set the LED off
delay(20); // wait for a second
digitalWrite(redLedPin, LOW); // set the LED off
delay(subdel); // wait for a second

}


//=================================================================================


17. blinks 5 times


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, LOW); // set the LED on
for (int i = 0; i <>

//=================================================================================


18. blink random amount


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
long rand = random(1,10);
digitalWrite(ledPin, LOW); // set the LED on
for (int i = 0; i <>

//=================================================================================


19. increase rate of blinking


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
long rand = random(1,10);
digitalWrite(ledPin, LOW); // set the LED on
for (int i = 0; i <>

//=================================================================================


20. increase then decrease rate of blinking


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;
int subdel = 500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
int i = 0;
long rand = random(1,10);
digitalWrite(ledPin, LOW); // set the LED on

while (i < i =" 0;">

//=================================================================================



21. output word, "blink"


int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
Serial.println("blink");
delay(200); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(200); // wait for a second
}


//=================================================================================



22. output colour of LED that is on


*/

int redLedPin = 13;// LED connected to digital pin 13
int yellowLedPin = 12;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(redLedPin, HIGH); // set the LED on
Serial.println("red");
delay(200); // wait for a second
digitalWrite(redLedPin, LOW); // set the LED off
delay(200); // wait for a second

digitalWrite(yellowLedPin, HIGH); // set the LED on
Serial.println("yellow");
delay(200); // wait for a second
digitalWrite(yellowLedPin, LOW);// set the LED off
delay(200); // wait for a second
}


//=================================================================================


30. Button push

/*
Button

Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 7.


The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.


created 2005
by DojoDave
modified 17 Jun 2009
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

//=================================================================================

31. reverse button

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED off:
digitalWrite(ledPin, LOW);
}
else {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
}

//=================================================================================

32. reverse button, showing text

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println("button has been pushed, LED is off");
}
else {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
}

//=========================================

34. 100 random numbers between 0 and 9

//creates 100 random numbers between 0 and 9 and outputs them
//to the screen.

const int maxNumber = 100;
const int maxValue = 8;
const int minValue = 0;
int randomNumber;

// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
for (int i = 0; i < randomnumber =" random(minValue,">
//=========================================

35. 100 random numbers between 0 and 9
in listed order

//creates 100 random numbers between 0 and 9 and outputs them
//to the screen.

const int maxNumber = 100;
const int maxValue = 8;
const int minValue = 1;
int randomNumber;


// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
for (int i = 0; i < randomnumber =" random(minValue," size="3">//=========================================

36. 100 random numbers between 0 and 9
in listed order with average

//creates 100 random numbers between 0 and 9 and outputs them
//to the screen.

const int maxNumber = 10000;
const int maxValue = 8;
const int minValue = 1;
int randomNumber;
int timeDelay;


// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
Serial.flush();
float sum = 0;
float average = 0;
for (int i = 0; i < randomnumber =" random(minValue," average =" sum/maxNumber;" size="3">//=========================================

37. baud rates

min - 4800
max - 19200


//=========================================

38. reading LDR with button


int buttonPin2 = 2;
int photocellPin = 0;
int photoCellReading;
int buttonState;

// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(buttonPin2, INPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH)
{
photoCellReading = analogRead(photocellPin);
Serial.println(photoCellReading);
delay(1000);
}

}

//=========================================

39. reading LDR with button
and listed results

int buttonPin2 = 2;
int photocellPin = 0;
int photoCellReading;
int buttonState;
int buttonPushCount = 0;

// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(buttonPin2, INPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{

buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH)
{
buttonPushCount ++;
photoCellReading = analogRead(photocellPin);
Serial.print("reading number ");
Serial.print(buttonPushCount);
Serial.print(" = ");
Serial.println(photoCellReading);
delay(1000);
}

}

//=========================================

54. data logging, no array or eeprom

int a = 0;
int value;
int readPin = 0;
boolean run = true;

void setup()
{
Serial.begin(9600);
pinMode(readPin, INPUT);

}

void loop()
{

readData();

while(run)
{

}
}
void readData()
{

for (int i = 0; i < value =" analogRead(readPin);" a =" a" a =" 0;" readpin =" 0;" run =" true;" i =" 0;" value =" intArray[i];" a =" a" i =" 0;" currvalue =" analogRead(readPin);">

int a = 1;
int value;
int readPin = 0;
boolean run = true;
void setup()
{
Serial.begin(9600);
pinMode(readPin, INPUT);

}

void loop()
{
storeData();
readData();

while(run)
{

}
}
void readData()
{

for (int i = 1; i <= 10; i++) { value = EEPROM.read(a); Serial.print(a); Serial.print("\t"); Serial.print(value); Serial.println(); a = a + 1; delay(500); } } void storeData() { for(int i = 1; i<=10; i++) { int currValue = analogRead(readPin); EEPROM.write(i, currValue); } delay(5000); } //========================================= 57. data logging with a "smallest value" function #include

int a = 1;
int value;
int readPin = 0;
boolean run = true;
void setup()
{
Serial.begin(9600);
pinMode(readPin, INPUT);

}

void loop()
{
storeData();
readData();
Serial.print("smallest value = ");
Serial.print(findSmallest());

while(run)
{

}
}
void readData()
{

for (int i = 1; i <= 10; i++) { value = EEPROM.read(a); Serial.print(a); Serial.print("\t"); Serial.print(value); Serial.println(); a = a + 1; delay(500); } } void storeData() { for(int i = 1; i<=10; i++) { int currValue = analogRead(readPin); EEPROM.write(i, currValue); } delay(5000); } int findSmallest() { int smallestValue = EEPROM.read(1); for(int i = 1; i <= 10; i++) { int tempValue = EEPROM.read(i); if (tempValue < smallestvalue =" tempValue;">

Thursday, March 18, 2010

40, 41. YaBB

40. Forum Post: III Arduino Contest

The fact that you can win money by creating enjoyable projects sounds very interesting. Even though I'm not anywhere close to that level of expertise, it's nice to know that there is a little money involved if I ever decided to become a competitive "arduino maker".


Link:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264155114







42. Write a short list of rules for a bulletin board like YABB. Watch some thread over two weeks and be ready to make a contribution - ???

Sunday, March 7, 2010

LED Project - Simon Says

Simon Says

Overview:
A simple memory game were players a shown a sequence of colours (red, green, yellow, and blue) that they must remember and repeat in the same order using four related buttons. Each time a sequence is correctly matched, the level in increased, and the sequence extended by one. When the sequence is incorrectly matched, the game ends, and is reset.

Fritz:










Video:


Code:
A simple memory game were players a shown a sequence of colours (red, green, yellow, and blue) that they must remember and repeat in the same order using four related buttons. Each time a sequence is correctly matched, the level in increased, and the sequence extended by one. When the sequence is incorrectly matched, the game ends, and is reset.

// constants won't change. They're used here to
// -set pin numbers:
// the number of the LED pins:
const int blueLedPin = 12;
const int yellowLedPin = 11;
const int greenLedPin = 10;
const int redLedPin = 9;
const int correctLedPin = 8;
const int incorrectLedPin = 7;
const int buzzerPin = 6;

// the number of the pushbutton pins:
const int blueButtonPin = 2;
const int yellowButtonPin = 3;
const int greenButtonPin = 4;
const int redButtonPin = 5;

const int smallestLedPinValue = 9;
const int highestLedPinValue = 12;
const int sequenceDelay = 500; //half a second
const int finishDelay = 3000; //three seconds
const int defaultLevel = 3;
// global variables will change:

int level = defaultLevel;


// -variables for reading the pushbutton status:
int blueButtonState = 0;
int yellowButtonState = 0;
int greenButtonState = 0;
int redButtonState = 0;

//memory arrays
int computerMemory[20]; // holds the computers colour sequence.
int playerMemory[20]; // holds the players sequence.

//==================================================================

void setup()
{
// initialize the LED pins as an output:
pinMode(blueLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(correctLedPin, OUTPUT);
pinMode(incorrectLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);

// initialize the pushbutton pins as an input:
pinMode(blueButtonPin, INPUT);
pinMode(yellowButtonPin, INPUT);
pinMode(greenButtonPin, INPUT);
pinMode(redButtonPin, INPUT);

Serial.begin(9600);
randomSeed(analogRead(0));
}

//==================================================================

void loop()
{
displaySequence();
playerSequence();
compareSequences();
}

//==================================================================

void displaySequence()
//displays and records colour sequence:
{
int randomLed;
for (int i = 0; i < level; i++)
{
randomLed = random(smallestLedPinValue,(highestLedPinValue + 1)); //creates a random number between the smallest and highest pin values.
computerMemory[i] = randomLed;
digitalWrite(randomLed, HIGH);//lights the random pin.
delay(sequenceDelay);
digitalWrite(randomLed, LOW);
delay(sequenceDelay);
}//end of for loop.
}//end of method.

//==================================================================

void playerSequence()
// waits for the player to push enough buttons to match the computer sequence. Each button pushed "lights up" its related LED and records
//the number of that LedPin in the "playerMemory" array.
//note to self*
{
int playerPushCount = 0;
int arrayCounter = 0;
while(playerPushCount < level)
{
blueButtonState = digitalRead(blueButtonPin);
yellowButtonState = digitalRead(yellowButtonPin);
greenButtonState = digitalRead(greenButtonPin);
redButtonState = digitalRead(redButtonPin);

if (blueButtonState == HIGH)
{
digitalWrite(blueLedPin, HIGH);
digitalWrite(buzzerPin, HIGH);
while(blueButtonState == HIGH)
{
blueButtonState = digitalRead(blueButtonPin);
}
playerMemory[arrayCounter] = blueLedPin;
arrayCounter++;
playerPushCount++;
digitalWrite(blueLedPin, LOW);
digitalWrite(buzzerPin, LOW);
}

if (redButtonState == HIGH)
{
digitalWrite(redLedPin, HIGH);
while(redButtonState == HIGH)
{
redButtonState = digitalRead(redButtonPin);
}
playerMemory[arrayCounter] = redLedPin;
arrayCounter++;
playerPushCount++;
digitalWrite(redLedPin, LOW);
}

if (yellowButtonState == HIGH)
{
digitalWrite(yellowLedPin, HIGH);
while(yellowButtonState == HIGH)
{
yellowButtonState = digitalRead(yellowButtonPin);
}
playerMemory[arrayCounter] = yellowLedPin;
arrayCounter++;
playerPushCount++;
digitalWrite(yellowLedPin, LOW);
}


if (greenButtonState == HIGH)
{
digitalWrite(greenLedPin, HIGH);
while(greenButtonState == HIGH)
{
greenButtonState = digitalRead(greenButtonPin);
}
playerMemory[arrayCounter] = greenLedPin;
arrayCounter++;
playerPushCount++;
digitalWrite(greenLedPin, LOW);
}

}
}

//==================================================================

void compareSequences()
//compares each element in arrays computerMemory and PlayerMemory. each match found adds "1" to "correct". If the number of correct choices equals
//the level (the level is also the amount of elements in a sequence), then the next level begins, otherwise, the player loses, their final score is displayed and the game is reset.
{
int correct = 0;
for (int i = 0; i < level; i++)
{
if (computerMemory[i] == playerMemory[i])
{
correct++;
}
}

if (correct == level)
{
level++;
digitalWrite(correctLedPin, HIGH);
delay(finishDelay);
digitalWrite(correctLedPin, LOW);
Serial.println("Well Done!");
}
else
{
Serial.print("Game Over!, you reached level ");
Serial.println(level);
level = defaultLevel;
digitalWrite(incorrectLedPin, HIGH);
delay(finishDelay);
digitalWrite(incorrectLedPin, LOW);
}
}


/* *i could have used an array of buttonstates and pins to stop duplicate code e.g.
for (i=0; i < numberOfButtons;i++)
{
while(buttonaarray[i] = HIGH)
LedPin[i] = HIGH
each ledpin in the array relates to a button in the button array. it wont work if they dont relate*/

Wednesday, March 3, 2010

youtube arduino LEDs

8x8 Arduino powered RGB LED Circuit with PWM

an arduino powering a home made LED driver circuit. The circuit uses 4 shift registers to drive 8x8x3 = 192 individual LEDs using only 3 pins (data,clock,latch) on the arduino. Pulse Width Modulation allows for 16 levels of each color on the board, hard to see in the video but lots of pretty colors are possible, including white.

link:
http://www.youtube.com/watch?v=j6nK33QI-So


24x16 RGB Display with Weather data from Yahoo and SHT11

Movie showing my 24x16 RGB Led panel. Based on 6 Sparkfun SPI controllable 8x8 Led panels with modified atmega8 firmware to allow some PWM on the LEDS. The panel is controlled by an Embedded Master running a C# .NET Micro Framework Program.

link:
http://www.youtube.com/watch?v=XZHkkvzg0EI&feature=related


Arduino LED-Cube

creates a variety of effects using a cube of LEDs.

link:
http://www.youtube.com/watch?v=SddZEChXdHU


Arduino Synth with LED-Control

creates a number of different sounds using five different controls. LEDs light up as each control is turned.

link:
http://www.youtube.com/watch?v=UJqY6U8fSmY&feature=related

43. Arduino Resources

Arduino projects






link:
http://www.arduinoprojects.com





Aruino Tutorial















link:
http://www.ladyada.net/learn/arduino/






Hack n Mod - Top 40 Arduino projects of the web


link:
http://hacknmod.com/hack/top-40-arduino-projects-of-the-web/









getting started with arduino
Link:
http://oreilly.com/catalog/9780596155520/preview#preview