Wednesday, July 21, 2010

fgdfg

dfgdfg

Robotics Tasks

1.) What is a robot?
  • A robot is an automatically guided machine which is able to do tasks on its own, almost always due to electronically-programmed instructions.
=============================================

2.) What are some early robots?
Atomic Robot Man




















Was one of the earliest known Robot toys from Japan. It is from the same time period (probably the 1940's) as the Tin Lilliput Robot. These early Robots are very primitive and very, very rare. Their makers are unknown.
=============================================

Thursday, June 17, 2010

Major Project - Ultrasonic sensor

Transmitter circuit















Receiver circuit
















Programe:

int ledPin = 13;
int numChanges = 0;
int MAX_TIME = 1000;
boolean changed = false;
boolean prevReadHigh = false;
int startTime;
int finishTime;


void setup() {

pinMode(ledPin, INPUT);
Serial.begin(9600);
}


void loop()
{

finishTime = (millis() + MAX_TIME);

numChanges = 0;
changed = false;
prevReadHigh = false;
while(millis() <= finishTime)
{
if (digitalRead(ledPin) == HIGH)
{
Serial.println("high");
if (prevReadHigh != true)
{
prevReadHigh = true;
numChanges++;

}
}
else
{
Serial.println("low");
if (prevReadHigh != false)
{
prevReadHigh = false;
numChanges++;
}
}

}
Serial.println(numChanges);
delay(100);
}

Process:

1: Set up both circuits on a single bread board
2: changed the voltage to the receiver from 9 volts to 5 volts so that the arduino could handle it. (still not sure what effect this had on the project)
3: wrote programe
4: realized that the receiver receives pulses (not just one consistent voltage) and therefor had to rewrite my programe to count the pulses.
5: tried using buzzers and LED's to get a signal from the transmitter but soon after realized that the pulses are to fast for ether of them to pick it up.
6: applied a "ground" to several IC pins after realizing they were not connected.
7: ended up getting what looked like a pulse on the LED and had some variance when I moved the transmitter closer to the receiver which lead me to believe that the transmitter was actually transmitting.
8: couldn't manage to read the pulses in the arduino due to a lack of voltage which I am still unsure of.

Sunday, May 2, 2010

Task check list

1) Create a blog.
- www.vinniees.blogspot.com



2) Put link into Moodle wiki. (Moodle not ready yet.)
- done



3)Fill in rest of your details on Moodle wiki
- done



4)Check out all the sites related to the list in the embedded notices blog.


Write a sentence about what each one does. You don't have to be very familiar with each one.
- Within the navigation




5) Find 4 more Arduino LED related videos in Youtube, BlipTV etc. Put a link and a two-sentence review about each one in your blog. Be prepared to talk about one or more of them.
- http://vinniees.blogspot.com/2010/03/youtube-arduino-leds.html



6) Establish a sketchpad folder in the D Drive or in a USB pen.
- done

7 - 22) programes
- http://vinniees.blogspot.com/2010/03/programmes.html

23) put at least one Arduino variety, like Freeduino, into this wiki with a screen shot and put a link and a comment back into your blog so that it can be verified.
- done

24) Put a link and comment about this page in your blog. Identify your LDR from your pack.
- http://vinniees.blogspot.com/2010/02/links.html

25) Start a Arduino key words page in your blog. Put every new key word with an explanation and example when you come across it.
- http://vinniees.blogspot.com/2010/02/arduino-keywords.html

26)
Run the ladayada photocell program that was handed out in class. Write it up in your blog about what you did and the program.
- Missed that class and didn'
t get hand out.

27) Same as 26 above but make some changes to improve it. Put your changes into a comment so that it's obvious what the differences are.
- - Missed that class and didn't get hand out.

28) Write a program to turn a LED on whenever the light is blocked to your LED. You will have to play around with several values.
- http://vinniees.blogspot.com/2010/03/programmes.html

29) Check out the wikiEducator site that has some example Arduino resources. Read the directions there about doing another one. Create one like it in your blog or create it in wikiEducator by registering and starting your own pages. If your resources page is not in your blog, create a heading and a link to it so that it can be marked.
- http://vinniees.blogspot.com/2010/03/arduino-resources.html

30 - 39) programes
- http://vinniees.blogspot.com/2010/03/programmes.html

40)Find an interesting article on the YABB news section and provide a screen shot and a short report on why you found it interesting.
- http://vinniees.blogspot.com/2010/03/yabb-registration.html

41) Register for YABB but don't
contribute yet. Take a screen shot of part of your registration process to confirm you've done it.
- http://vinniees.blogspot.com/2010/03/yabb-registration.html

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.
- Not sure want you meant by "rules" here

43)
Write a list of four good project sites and include a link and a screen shot for each with a comment in your blog.
- http://vinniees.blogspot.com/2010/03/arduino-resources.html

44) Present to the class a report on one of your assigned devices. You need to tell us what it does and give a little demo of it working on a simple Arduino project. Include in your talk at least three Impress or PowerPoint slides on a USB pen or similar.
- Done with Glenn

45) Explore the way your infrared transmitter sends pulses to the receiver. Set up a little demonstration to be marked in class. You may share this project with another person but both members have to know what's going on. Transmission from one Arduino to another is especially excellent.
- done in class

46 - 50) Using two Arduino's
- done in class

Sender:
int ledPin = 13;
boolean high = false;


void setup() {

pinMode(ledPin, OUTPUT);
pinMode(0, OUTPUT);

}

void loop()
{
if (high)
{
digitalWrite(0, LOW);
digitalWrite(ledPin, LOW);
high = false;

}
else
{

digitalWrite(0, HIGH);
digitalWrite(ledPin, HIGH);
high = true;
}
delay(1000);
}


Receiver
// Communication Pins
const int rxPin = 2;
const int txPin = 13;


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

// Initialize the Rx and Tx pins
// Traffic Light LEDs
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
}

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

void loop()
{
//int i = 1;
pollRxPin();
flipTxPin();
//i++;
delay(1000);
}

void pollRxPin()
{
if( digitalRead(rxPin) == HIGH )
{
//Serial.print(i);
//Serial.print(": ");

Serial.println('H');
digitalWrite( txPin, HIGH );
}
else
{
//Serial.print(i);
//Serial.print(": ");
Serial.println('L');
digitalWrite( txPin, LOW );
}
}

void flipTxPin()
{
}




51. EEPROM read













52. EEPROM Write













53. EEPROM fill













54 - 58 in programmes

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

Sunday, February 28, 2010

Arduino Keywords

setup:
sets everything up.

loop:
an infinite loop were your main programe goes.

Serial.print:
prints text to screen with out creating a new line

Serial.println:
prints text to screen and creates a new line.

delay(x):
delays the programe for "x" amount of milliseconds.

pinMode():
sets the pin to input or output.

digitalRead()
:
returns the current (or something like that) of the pin given.

Arduino ScrewShield - Arduino variation


Arduino ScrewShield

The ScrewShield extends all pins of the Arduino out to 3.5mm pitch screw terminals. Both sides of the shield are broken out to the side of the Arduino, to allow access to everything on the main Arduino board. Stacking headers are also included so you can pile more shields on top.

Saturday, February 20, 2010

Links

Atmel:
http://www.atmel.com/

Arduino:
http://www.arduino.cc/

Arduino Forum:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl

Moodle:
http://moodle.op.ac.nz/course/view.php?id=1301

MindKits:
http://www.mindkits.co.nz/

photocells:
http://www.ladyada.net/learn/sensors/cds.html

Basically gives you a bunch of info about the LDR and some small examples of using one.

The Arduino

Intro to the Arduino

Link: http://www.youtube.com/watch?v=PeScmRwzQho

These guys use a very casual approach to get there information accross. Although there a little silly, there information is easily understood due to there use of simple terms and clear descriptions. perfect for introducing people who may not have had much experience in this area before to the Arduino.

Thursday, February 18, 2010

PeerWise

Allows students to ask questions, learn answers and share what they know with other students.

Similar to Microsoft Office, includes software such as word processing, spreadsheets, presentations, graphics and databases.

fritzing


Fritzing is an open-source initiative to support designers, artists, researchers and hobbyists to take the step from physical prototyping to actual product.

Could be useful for testing.

Chip8


an interpreted programming language. used to make classic video games such as Pong and Tetris.

WikiEducator

The WikiEducator is an evolving community intended for the collaborative:

planning of education projects linked with the development of free content;
development of free content on Wikieducator for e-learning;
work on building open education resources (OERs) on how to create OERs.

GNU gcc

Originally written for an operating system. Supports a number of languages including C++ and Java.

Processing environment

A Basic programing with some basic features like play, stop, save, open, new etc. includes a text editor, a compiler and a display window.