Wednesday, July 21, 2010

Some Of The First Robots

Eliza - A computer programmed robot that answered questions with questions. It had 240 lines of code.

Unimate Robot - The first industrial robot built in 1961. It took die casting from machines and performed weilding similar to a human task.

What Is A Robot?

A robot is a machine that can be programmed or controlled to do a specific task such as walking or flying. This is usually powered by electricity and can resemble human tasks.

Thursday, June 3, 2010

Task 59 - Data Logging of Light Over 24 Hours

I found this was not very accurate as EEPROM was not storing numbers correctly. If a number was over 300 it would not save it into EEPROM, but would save another number all together. However These are my results





#include
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int value;
int a = 0;



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


for (int i=0; i <25; i++){
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
EEPROM.write(i, photocellReading);
delay(3600000);

value = EEPROM.read(i);

Serial.print(i);
Serial.print("\t");
Serial.print(value);
Serial.println();



}


for (int i=0; i <25; i++){

value = EEPROM.read(i);

Serial.print(i);
Serial.print("\t");
Serial.print(value);
Serial.println();



}
}

void loop(){

}

Graphed Results (Analog Results, not ones stored in EEPROM):

Major Project - Pong Through One Matrix Display

video

/*This is a Pong game used on one Matrix display using analog
potentionmeters to move the paddles. This game was helped using
similar code from Tom Igoe (for pong) and scrolling message from
the website http://www.tinyurl.com/yhwxv6h*/




// define the edges of the screen:
#define LEFT 0
#define RIGHT 7
#define TOP 0
#define BOTTOM 7

int speed = 15; //number of times to repeat each frame
int pauseDelay = 500; //microseconds to leave each row on before moving to the next
int index = 0; //this is the current charachter in the string being displayed
int offset = 0; //this is how many columns it is offset by

const int A = 0; const int B = 1; const int C = 2; const int D = 3; const int E = 4;
const int F = 5; const int G = 6; const int H = 7; const int I = 8; const int J = 9;
const int K = 10; const int L =11; const int M = 12; const int N = 13; const int O = 14;
const int P = 15; const int Q =16; const int R = 17; const int S = 18; const int T = 19;
const int U = 20; const int V =21; const int W = 22; const int X = 23; const int Y = 24;
const int Z = 25; // Letters to be displayed

char requestString1[] = " Left Player Wins "; // Request String for left player
char requestString2[] = " Right Player Wins "; // Request String for right player

int matrixCount = 0;

int rowA[] ={11,14,16,3,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix

//An Array defining which pin each row is attached to

int colA[] = {8,6,4,2,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix


//An Array defining which pin each col is attached to


//Punctuation
const int COL =26; const int DASH = 27; const int BRA2 = 28; const int _ = 29; const int LINE = 34;
const int DOT =36;

//Extra Charchters
const int FULL =30; const int CHECK = 31; const int A3 = 32; const int TEMP = 33;
const int SMILE =35; const int COLDOT = 36;


//The array used to hold a bitmap of the display
//(if you wish to do something other than scrolling marque change the data in this
//variable then display)
byte data[] = {0,0,0,0,0,0,0,0};

//The alphabet
//Each Charachter is an 8 x 7 bitmap where 1 is on and 0 if off
const int _A[] = {B0001000,
B0010100,
B0100010,
B1000001,
B1111111,
B1000001,
B1000001,
B0000000};

const int _B[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100001,
B0100001,
B1111110,
B0000000};

const int _C[] = {B0011111,
B0100000,
B1000000,
B1000000,
B1000000,
B0100000,
B0011111,
B0000000};

const int _D[] = {B1111100,
B0100010,
B0100001,
B0100001,
B0100001,
B0100010,
B1111100,
B0000000};

const int _E[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1111111,
B0000000};

const int _F[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1000000,
B0000000};

const int _G[] = {B0011111,
B0100000,
B1000000,
B1001111,
B1000001,
B0100001,
B0011111,
B0000000};

const int _H[] = {B1000001,
B1000001,
B1000001,
B1111111,
B1000001,
B1000001,
B1000001,
B0000000};

const int _I[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B1111111,
B0000000};

const int _J[] = {B0001111,
B0000001,
B0000001,
B0000001,
B0000001,
B1000001,
B0111110,
B0000000};

const int _K[] = {B1000011,
B1000100,
B1001000,
B1110000,
B1001000,
B1000100,
B1000011,
B0000000};

const int _L[] = {B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1111111,
B0000000};

const int _M[] = {B1110110,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0000000};

const int _N[] = {B1000001,
B1100001,
B1010001,
B1001001,
B1000101,
B1000011,
B1000001,
B0000000};

const int _O[] = {B0011100,
B0100010,
B1000001,
B1001001,
B1000001,
B0100010,
B0011100,
B0000000};

const int _P[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100000,
B0100000,
B0100000,
B0000000};

const int _Q[] = {B0011100,
B0100010,
B1000001,
B1000001,
B1000101,
B0100010,
B0011101,
B0000000};

const int _R[] = {B1111110,
B0100001,
B0100001,
B0101110,
B0100100,
B0100010,
B0100001,
B0000000};

const int _S[] = {B0111111,
B1000000,
B1000000,
B0111110,
B0000001,
B0000001,
B1111110,
B0000000};

const int _T[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _U[] = {B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B0111110,
B0000000};

const int _V[] = {B1000001,
B1000001,
B1000001,
B1000001,
B0100010,
B0010100,
B0001000,
B0000000};

const int _W[] = {B1000001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0110110,
B0000000};

const int _X[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0010100,
B0100010,
B1000001,
B0000000};

const int _Y[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _Z[] = {B1111111,
B0000010,
B0000100,
B0111110,
B0010000,
B0100000,
B1111111,
B0000000};

const int _COL[] = {B0000000,
B0011000,
B0011000,
B0000000,
B0011000,
B0011000,
B0000000,
B0000000};

const int _DASH[] = {B0000000,
B0000000,
B0000000,
B0111110,
B0000000,
B0000000,
B0000000,
B0000000};

const int _BRA2[] = {B0010000,
B0001000,
B0000100,
B0000100,
B0001000,
B0010000,
B0000000,
B0000000};

const int __[] = {B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000};

const int _FULL[] = {B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111};

const int _CHECK[] = {B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0000000};

const int _A3[] = {B0111110,
B0000001,
B0000001,
B0001111,
B0000001,
B1000001,
B0111110,
B0000000};

const int _TEMP[] = {B0000011,
B0011111,
B0111111,
B1111110,
B1111111,
B0011111,
B0000011,
B0000000};

const int _LINE[] = {B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000000};

const int _SMILE[] = {B1100110,
B1100110,
B0000000,
B0011100,
B1000001,
B0100010,
B0011100,
B0000000};


const int _DOT[] = {B0000000,
B0000000,
B0000000,
B0000000,
B1100000,
B1100000,
B0000000,
B0000000};

const int _COLDOT[] = {B0000000,
B0110000,
B0110000,
B0000000,
B0110011,
B0110011,
B0000000,
B0000000};

//Load the bitmap charachters into an array (each charachters position corresponds to its previously defined index (ie _A (a's bitmap)
//is at index 0 and A = 0 so letters[A] will return the 'A' bitmap)
const int* letters[] = {_A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_P,_Q,_R,_S,_T,_U,_V,_W,_X,_Y,_Z,_COL,_DASH,_BRA2,__, _FULL, _CHECK, _A3, _TEMP, _LINE, _SMILE, _DOT, _COLDOT};

//Setup runs once when power is applied



int pixels[8][8]; // 2-dimensional array of pixels

// 2-dimensional array of row pin numbers (for two matrices):
int row[1][8] = {11,14,16,3,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix

// 2-dimensional array of column pin numbers (for two matrices):
int col[1][8] = {8,6,4,2,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix

int ballX = 3; // X position of the ball
int ballY = 4; // Y position of the ball
int ballDirectionY = 1; // X direction of the ball
int ballDirectionX = 1; // Y direction of the ball
int lCount = 0; // count score for left paddle
int rCount = 0; // count score for right paddle

int rightPaddleY = 0; // X position of the center of the right paddle
int leftPaddleY = 0; // Y position of the center of the right paddle

long timeStamp = 0; // time stamp to control the pauses between ball moves
long interval = 250; // interval between ball moves, in milliseconds
boolean gamePaused = false; // state of the game

void setup() {
// initialize the I/O pins as outputs:

// iterate over the matrix:
for (int thisMatrix = 0; thisMatrix < 1; thisMatrix++) {
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisMatrix][thisPin], OUTPUT);
pinMode(row[thisMatrix][thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisMatrix][thisPin], HIGH);
}

}
newGame();

}

void loop() {
// read input:
readSensors();
// move the ball:
if (gamePaused) {
if (millis() - timeStamp > interval*10) {
// if enough time has passed, start the game again:
gamePaused = false;
}
}
// if the game isn't paused, and enough time between ball moves
// has passed, move the ball and update the timestamp:
else {
if (millis() - timeStamp > interval) {
moveBall();
timeStamp = millis();
}
}
// draw the screen:
refreshScreen();
}

void newGame() {

for (int thisMatrix = 0; thisMatrix < 1; thisMatrix++) {
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
digitalWrite(row[thisMatrix][thisPin], HIGH);
digitalWrite(col[thisMatrix][thisPin], LOW);
}
delay(200);
for (int thisPin = 0; thisPin < 8; thisPin++) {
digitalWrite(row[thisMatrix][thisPin], LOW);
digitalWrite(col[thisMatrix][thisPin], LOW);
}
delay(100);

}




}

void readSensors() {
// set the left paddle to off:
setPaddle(LEFT, leftPaddleY, HIGH);
// set the right paddle to off:
setPaddle(RIGHT, rightPaddleY, HIGH);

// read the sensors for X and Y values:
leftPaddleY = map(analogRead(4), 0, 1023, 0, 7);
rightPaddleY = map(analogRead(5), 0, 1023, 0, 7);

// set the left paddle to on:
setPaddle(LEFT, leftPaddleY, LOW);
// set the right paddle to on:
setPaddle(RIGHT, rightPaddleY, LOW);
}

void setPaddle(int paddleX, int paddleY, int state) {
// set the last right paddle to on:
pixels[paddleX][paddleY] = state;
// set the bottom pixel of the paddle:
if (paddleY < BOTTOM) {
pixels[paddleX][paddleY+1] = state;
}

// set the top pixel of the paddle:
if (paddleY > TOP) {
pixels[paddleX][paddleY-1] = state;
}
}

void moveBall() {
// check to see if the ball is in the horizontal range
// of the paddles:

// right:
if (ballX >= RIGHT - 1) {
// if the ball's next Y position is between
// the top and bottom of the paddle, reverse its X direction:
if ((ballY + ballDirectionY >= rightPaddleY - 1)
&& (ballY + ballDirectionY <= rightPaddleY +1)) {
// reverse the ball horizontal direction:
ballDirectionX = -ballDirectionX;
}
}

// left:
if (ballX <= LEFT + 1) {
// if the ball's next Y position is between
// the top and bottom of the paddle, reverse its X direction:
if ((ballY + ballDirectionY >= leftPaddleY -1 )
&& (ballY + ballDirectionY <= leftPaddleY +1 )) {
// reverse the ball horizontal direction:
ballDirectionX = -ballDirectionX;
}
}

// if the ball goes off the screen bottom,
// reverse its Y direction:
if (ballY == BOTTOM) {
ballDirectionY = -ballDirectionY;
}
// if the ball goes off the screen top,
// reverse its X direction:
if (ballY == TOP) {
ballDirectionY = -ballDirectionY;
}

// clear the ball's previous position:
pixels[ballX][ballY] = HIGH;

// if the ball goes off the screen left or right:
if ((ballX == LEFT) || (ballX == RIGHT)) {
if (ballX == LEFT) {
lCount = lCount+1;
if (lCount == 3){
matrixCount = 1;
for (int i=0; i<136; i++){
updateMatrix();
}
lCount = 0;
rCount = 0;
newGame();
}

}else if (ballX==RIGHT){
rCount = rCount+1;
if (rCount == 3){
matrixCount = 2;
for (int i=0; i<144; i++){
updateMatrix();
}
lCount = 0;
rCount = 0;
newGame();
}
}

// reset the ball:
ballX = 4;
ballY = 4;
// pause and note the time you paused:
gamePaused = true;
timeStamp = millis();
}
// increment the ball's position in both directions:
ballX = ballX + ballDirectionX;
ballY = ballY + ballDirectionY;

// if the game isn't paused, set the ball
// in its new position:
if (!gamePaused) {
// set the new position:
pixels[ballX][ballY] = LOW;
}
}

void refreshScreen() {
// iterate over the matrices:
for (int thisMatrix = 0; thisMatrix < 1; thisMatrix++) {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisMatrix][thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow+ (thisMatrix * 8)][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisMatrix][thisCol], thisPixel);
// turn the pixel off:
digitalWrite(col[thisMatrix][thisCol], HIGH);
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisMatrix][thisRow], LOW);
}
}
}
void updateMatrix(){
loadSprite();
showSprite(speed);
}

const int powers[] = {1,2,4,8,16,32,64,128};

//Loads the current scroll state frame into the data[] display array
void loadSprite(){
if (matrixCount == 1){
int currentChar = getChar(requestString1[index]);
int nextChar = getChar(requestString1[index+1]);

for(int row=0; row < 8; row++){ //iterate through each row
data[row] = 0; //reset the row we're working on
for(int column=0; column < 8; column++){ //iterate through each column
data[row] = data[row] + ((powers[column] & (letters[currentChar][row] << offset))); //loads the current charachter offset by offset pixels
data[row] = data[row] + (powers[column] & (letters[nextChar][row] >> (8-offset) )); //loads the next charachter offset by offset pixels
}
}
offset++; //increment the offset by one row
if(offset==8){offset = 0; index++; if(index==sizeof(requestString1)-2){index=0;}} //if offset is 8 load the next charachter pair for the next time through




}else if (matrixCount == 2){
int currentChar = getChar(requestString2[index]);
int nextChar = getChar(requestString2[index+1]);

for(int row=0; row < 8; row++){ //iterate through each row
data[row] = 0; //reset the row we're working on
for(int column=0; column < 8; column++){ //iterate through each column
data[row] = data[row] + ((powers[column] & (letters[currentChar][row] << offset))); //loads the current charachter offset by offset pixels
data[row] = data[row] + (powers[column] & (letters[nextChar][row] >> (8-offset) )); //loads the next charachter offset by offset pixels
}
}
offset++; //increment the offset by one row
if(offset==8){offset = 0; index++; if(index==sizeof(requestString2)-2){index=0;}} //if offset is 8 load the next charachter pair for the next time through





}
}
void showSprite(int speed2){
for(int iii = 0; iii < speed2; iii++){ //show the current frame speed2 times
for(int column = 0; column < 8; column++){ //iterate through each column
for(int i = 0; i < 8; i++){
digitalWrite(rowA[i], LOW); //turn off all row pins
}
for(int i = 0; i < 8; i++){ //Set only the one pin
if(i == column){ digitalWrite(colA[i], LOW);} //turns the current row on
else{ digitalWrite(colA[i], HIGH); }//turns the rest of the rows off
}

for(int row = 0; row < 8; row++){ //iterate through each pixel in the current column
int bit = (data[column] >> row) & 1;
if(bit == 1){
digitalWrite(rowA[row], HIGH); //if the bit in the data array is set turn the LED on
}

}
delayMicroseconds(pauseDelay); //leave the column on for pauseDelay microseconds (too high a delay causes flicker)
}
}
}

//returns the index of a given charachter
//for converting from a string to a lookup in our array of charachter bitmaps
int getChar(char charachter){
int returnValue = Z;
switch(charachter){
case 'A': returnValue = A; break;
case 'a': returnValue = A; break;
case 'B': returnValue = B; break;
case 'b': returnValue = B; break;
case 'C': returnValue = C; break;
case 'c': returnValue = C; break;
case 'D': returnValue = D; break;
case 'd': returnValue = D; break;
case 'E': returnValue = E; break;
case 'e': returnValue = E; break;
case 'F': returnValue = F; break;
case 'f': returnValue = F; break;
case 'G': returnValue = G; break;
case 'g': returnValue = G; break;
case 'H': returnValue = H; break;
case 'h': returnValue = H; break;
case 'I': returnValue = I; break;
case 'i': returnValue = I; break;
case 'J': returnValue = J; break;
case 'j': returnValue = J; break;
case 'K': returnValue = K; break;
case 'k': returnValue = K; break;
case 'L': returnValue = L; break;
case 'l': returnValue = L; break;
case 'M': returnValue = M; break;
case 'm': returnValue = M; break;
case 'N': returnValue = N; break;
case 'n': returnValue = N; break;
case 'O': returnValue = O; break;
case 'o': returnValue = O; break;
case 'P': returnValue = P; break;
case 'p': returnValue = P; break;
case 'Q': returnValue = Q; break;
case 'q': returnValue = Q; break;
case 'R': returnValue = R; break;
case 'r': returnValue = R; break;
case 'S': returnValue = S; break;
case 's': returnValue = S; break;
case 'T': returnValue = T; break;
case 't': returnValue = T; break;
case 'U': returnValue = U; break;
case 'u': returnValue = U; break;
case 'V': returnValue = V; break;
case 'v': returnValue = V; break;
case 'W': returnValue = W; break;
case 'w': returnValue = W; break;
case 'X': returnValue = X; break;
case 'x': returnValue = X; break;
case 'Y': returnValue = Y; break;
case 'y': returnValue = Y; break;
case 'Z': returnValue = Z; break;
case 'z': returnValue = Z; break;
case ' ': returnValue = _; break;
case '3': returnValue = A3; break;
case '<': returnValue = TEMP; break;
case '*': returnValue = FULL; break;
case '|': returnValue = LINE; break;
case '_': returnValue = _; break;
case ':': returnValue = COL; break;
case '-': returnValue = DASH; break;
case ')': returnValue = BRA2; break;
case '%': returnValue = SMILE; break;
case '.': returnValue = DOT; break;
case '^': returnValue = COLDOT; break;
}
return returnValue;
}

Sunday, May 30, 2010

Task 58 - Finding Average & Biggest Number With Suitable Message

#include EEPROM.h
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;// the analog reading from the analog resistor divider
int value;
int a = 0;
int smallest = 0;
int biggest = 0;
float average = 0;



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


for (int i=0; i <10; i++){
photocellReading = analogRead(photocellPin);
if (photocellReading < smallest){
smallest = photocellReading;
}
if (photocellReading > biggest){
biggest = photocellReading;
}
average = average + photocellReading;
EEPROM.write(i, photocellReading);
delay(500);
}

for (int i=0; i <10; i++){
value = EEPROM.read(a);
Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 10){
a = 0;
delay(500);
}
}
Serial.println("The Smallest Value Was: " + smallest); // displays smallest value
Serial.println("The Biggest Value Was: " + biggest); // displays biggest value
average = average/10; // calculates mean
Serial.println("The Average/Mean Was: " + average); // displays average value
}

void loop(){
}

Task 57 - Finding smallest Value With Suitable Message.

#include EEPROM.h
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;// the analog reading from the analog resistor divider
int value;
int a = 0;
int smallest = 0;



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


for (int i=0; i <10; i++){
photocellReading = analogRead(photocellPin);
if (photocellReading < smallest){
smallest = photocellReading;
}
EEPROM.write(i, photocellReading);
delay(500);
}

for (int i=0; i <10; i++){
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 10){
a = 0;
delay(500);
}
}
Serial.println("The Smallest Value Was: " + smallest);
}

void loop(){
}

Sunday, May 16, 2010

Task 56 - Data Logging to EEPROM

#include EEPROM.h
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;// the analog reading from the analog resistor divider];
//int mySamples[10];
int value;
int a = 0;



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


for (int i=0; i <10; i++){
photocellReading = analogRead(photocellPin);
//mySamples[i] = (photocellReading);
EEPROM.write(i, photocellReading);
delay(500);
}

for (int i=0; i <10; i++){
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 10){
a = 0;
delay(500);
}
}
}

void loop(){
}

Task 55 - Data Logging with Array

int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;// the analog reading from the analog resistor divider];
int mySamples[10];

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


for (int i=0; i <10; i++){
photocellReading = analogRead(photocellPin);
mySamples[i] = (photocellReading);
delay(500);
}

for (int i=0; i <10; i++){
Serial.print("Analog reading = ");
Serial.println(mySamples[i]);
}
}

void loop(){
}

Task 54 - Data logging

int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider

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


for (int i=0; i <10; i++){
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
delay(500);
}
}

void loop(){
}

Sunday, May 9, 2010

Minor Project - Keyboard input, Matrix Display Output

video


or http://www.youtube.com/watch?v=ysy3eYsyBtQ


The below code is what I used for my minor project:

#include "ps2.h"

#define PS2_KC_BKSP 0x08
#define PS2_KC_UP 0x81
#define PS2_KC_DOWN 0x82
#define PS2_KC_LEFT 0x83
#define PS2_KC_RIGHT 0x84
#define PS2_KC_PGDN 0x85
#define PS2_KC_PGUP 0x86
#define PS2_KC_END 0x87
#define PS2_KC_HOME 0x88
#define PS2_KC_INS 0x89
#define PS2_KC_DEL 0x8A
#define PS2_KC_ESC 0x8B
#define PS2_KC_CLON 0x8C // caps_lock on
#define PS2_KC_CLOFF 0x8D // caps_lock off

/*
* Pin 2 is the ps2 data pin, pin 3 is the clock pin
*/

PS2 kbd(3, 2);
bool ps2Keyboard_release = false;
bool ps2Keyboard_extend = false;
bool cmd_ack_byte_ok = false;
bool ps2Keyboard_shift = false;
bool ps2Keyboard_alt = false;
bool ps2Keyboard_caps_lock = false;
bool ps2Keyboard_ctrl = false;

byte ps2Keyboard_CharBuffer = 0;

byte code;


int count = 0;

int speed = 20; //number of times to repeat each frame
int pauseDelay = 500; //microseconds to leave each row on before moving to the next

//byte result = ps2Keyboard_CharBuffer;
char incomingByte;
//char str1[] = " ";

char requestString[100];//The string to display

char character; //to change the message in code you right yourself simply
//change this data and reset index and offset to 0
//Variables used for scrolling (both start at 0
int index = 0; //this is the current charachter in the string being displayed
int offset = 0; //this is how many columns it is offset by

//Pin Definitions
int rowA[] ={11,14,16,18,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix
//{11,14,16,18,3,5,7,9};//An Array defining which pin each row is attached to
//(rows are common anode (drive HIGH))
int colA[] = {8,6,4,19,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix
//{10,12,15,17,2,4,6,8}; //An Array defining which pin each column is attached to
//(columns are common cathode (drive LOW))

//Constants defining each charachters position in an array of integer arrays
//Letters
const int A = 0; const int B = 1; const int C = 2; const int D = 3; const int E = 4;
const int F = 5; const int G = 6; const int H = 7; const int I = 8; const int J = 9;
const int K = 10; const int L =11; const int M = 12; const int N = 13; const int O = 14;
const int P = 15; const int Q =16; const int R = 17; const int S = 18; const int T = 19;
const int U = 20; const int V =21; const int W = 22; const int X = 23; const int Y = 24;
const int Z = 25;

//Punctuation
const int COL =26; const int DASH = 27; const int BRA2 = 28; const int _ = 29; const int LINE = 34;
const int DOT =36;

//Extra Charchters
const int FULL =30; const int CHECK = 31; const int A3 = 32; const int TEMP = 33;
const int SMILE =35; const int COLDOT = 36;

//char requestString[] = "";
//The array used to hold a bitmap of the display
//(if you wish to do something other than scrolling marque change the data in this
//variable then display)
byte data[] = {0,0,0,0,0,0,0,0};

//The alphabet
//Each Charachter is an 8 x 7 bitmap where 1 is on and 0 if off
const int _A[] = {B0001000,
B0010100,
B0100010,
B1000001,
B1111111,
B1000001,
B1000001,
B0000000};

const int _B[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100001,
B0100001,
B1111110,
B0000000};

const int _C[] = {B0011111,
B0100000,
B1000000,
B1000000,
B1000000,
B0100000,
B0011111,
B0000000};

const int _D[] = {B1111100,
B0100010,
B0100001,
B0100001,
B0100001,
B0100010,
B1111100,
B0000000};

const int _E[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1111111,
B0000000};

const int _F[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1000000,
B0000000};

const int _G[] = {B0011111,
B0100000,
B1000000,
B1001111,
B1000001,
B0100001,
B0011111,
B0000000};

const int _H[] = {B1000001,
B1000001,
B1000001,
B1111111,
B1000001,
B1000001,
B1000001,
B0000000};

const int _I[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B1111111,
B0000000};

const int _J[] = {B0001111,
B0000001,
B0000001,
B0000001,
B0000001,
B1000001,
B0111110,
B0000000};

const int _K[] = {B1000011,
B1000100,
B1001000,
B1110000,
B1001000,
B1000100,
B1000011,
B0000000};

const int _L[] = {B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1111111,
B0000000};

const int _M[] = {B1110110,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0000000};

const int _N[] = {B1000001,
B1100001,
B1010001,
B1001001,
B1000101,
B1000011,
B1000001,
B0000000};

const int _O[] = {B0011100,
B0100010,
B1000001,
B1001001,
B1000001,
B0100010,
B0011100,
B0000000};

const int _P[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100000,
B0100000,
B0100000,
B0000000};

const int _Q[] = {B0011100,
B0100010,
B1000001,
B1000001,
B1000101,
B0100010,
B0011101,
B0000000};

const int _R[] = {B1111110,
B0100001,
B0100001,
B0101110,
B0100100,
B0100010,
B0100001,
B0000000};

const int _S[] = {B0111111,
B1000000,
B1000000,
B0111110,
B0000001,
B0000001,
B1111110,
B0000000};

const int _T[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _U[] = {B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B0111110,
B0000000};

const int _V[] = {B1000001,
B1000001,
B1000001,
B1000001,
B0100010,
B0010100,
B0001000,
B0000000};

const int _W[] = {B1000001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0110110,
B0000000};

const int _X[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0010100,
B0100010,
B1000001,
B0000000};

const int _Y[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _Z[] = {B1111111,
B0000010,
B0000100,
B0111110,
B0010000,
B0100000,
B1111111,
B0000000};

const int _COL[] = {B0000000,
B0011000,
B0011000,
B0000000,
B0011000,
B0011000,
B0000000,
B0000000};

const int _DASH[] = {B0000000,
B0000000,
B0000000,
B0111110,
B0000000,
B0000000,
B0000000,
B0000000};

const int _BRA2[] = {B0010000,
B0001000,
B0000100,
B0000100,
B0001000,
B0010000,
B0000000,
B0000000};

const int __[] = {B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000};

const int _FULL[] = {B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B0000000};

const int _CHECK[] = {B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0000000};

const int _A3[] = {B0111110,
B0000001,
B0000001,
B0001111,
B0000001,
B1000001,
B0111110,
B0000000};

const int _TEMP[] = {B0000011,
B0011111,
B0111111,
B1111110,
B1111111,
B0011111,
B0000011,
B0000000};

const int _LINE[] = {B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000000};

const int _SMILE[] = {B1100110,
B1100110,
B0000000,
B0011100,
B1000001,
B0100010,
B0011100,
B0000000};


const int _DOT[] = {B0000000,
B0000000,
B0000000,
B0000000,
B1100000,
B1100000,
B0000000,
B0000000};

const int _COLDOT[] = {B0000000,
B0110000,
B0110000,
B0000000,
B0110011,
B0110011,
B0000000,
B0000000};

//Load the bitmap charachters into an array (each charachters position corresponds to its previously defined index (ie _A (a's bitmap)
//is at index 0 and A = 0 so letters[A] will return the 'A' bitmap)
const int* letters[] = {_A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_P,_Q,_R,_S,_T,_U,_V,_W,_X,_Y,_Z,_COL,_DASH,_BRA2,__, _FULL, _CHECK, _A3, _TEMP, _LINE, _SMILE, _DOT, _COLDOT};

//Setup runs once when power is applied

// val : bit_2=caps_lock, bit_1=num_lock, bit_0=scroll_lock
void kbd_set_lights(byte val) {
kbd.write(0xED);
kbd.read(); // pull out the ack byte
kbd.write(val); // now send the data
}

byte lookupCode() {
byte result = ps2Keyboard_CharBuffer;

// Use a switch for the code to character conversion.
// This is fast and actually only uses 4 bytes per simple line
switch (result) {
case 0x1C: result = 'a'; break;
case 0x32: result = 'b'; break;
case 0x21: result = 'c'; break;
case 0x23: result = 'd'; break;
case 0x24: result = 'e'; break;
case 0x2B: result = 'f'; break;
case 0x34: result = 'g'; break;
case 0x33: result = 'h'; break;
case 0x43: result = 'i'; break;
case 0x3B: result = 'j'; break;
case 0x42: result = 'k'; break;
case 0x4B: result = 'l'; break;
case 0x3A: result = 'm'; break;
case 0x31: result = 'n'; break;
case 0x44: result = 'o'; break;
case 0x4D: result = 'p'; break;
case 0x15: result = 'q'; break;
case 0x2D: result = 'r'; break;
case 0x1B: result = 's'; break;
case 0x2C: result = 't'; break;
case 0x3C: result = 'u'; break;
case 0x2A: result = 'v'; break;
case 0x1D: result = 'w'; break;
case 0x22: result = 'x'; break;
case 0x35: result = 'y'; break;
case 0x1A: result = 'z'; break;
case 0x29: result = ' '; break;


// Reset the shift counter for unexpected values, to get back into sync
// This allows for hot plugging a keyboard in and out
default: delay(500); // but wait a bit in case part way through a shift
ps2Keyboard_shift = false;
ps2Keyboard_ctrl = false;
ps2Keyboard_alt = false;
ps2Keyboard_extend = false;
ps2Keyboard_release = false;
ps2Keyboard_caps_lock = false;
} // end switch(result)

// done with the character
ps2Keyboard_CharBuffer = 0;
return(result);
}
int getChar(char lookupCode){
int returnValue = _;
switch(lookupCode){
case 'A': returnValue = A; break;
case 'a': returnValue = A; break;
case 'B': returnValue = B; break;
case 'b': returnValue = B; break;
case 'C': returnValue = C; break;
case 'c': returnValue = C; break;
case 'D': returnValue = D; break;
case 'd': returnValue = D; break;
case 'E': returnValue = E; break;
case 'e': returnValue = E; break;
case 'F': returnValue = F; break;
case 'f': returnValue = F; break;
case 'G': returnValue = G; break;
case 'g': returnValue = G; break;
case 'H': returnValue = H; break;
case 'h': returnValue = H; break;
case 'I': returnValue = I; break;
case 'i': returnValue = I; break;
case 'J': returnValue = J; break;
case 'j': returnValue = J; break;
case 'K': returnValue = K; break;
case 'k': returnValue = K; break;
case 'L': returnValue = L; break;
case 'l': returnValue = L; break;
case 'M': returnValue = M; break;
case 'm': returnValue = M; break;
case 'N': returnValue = N; break;
case 'n': returnValue = N; break;
case 'O': returnValue = O; break;
case 'o': returnValue = O; break;
case 'P': returnValue = P; break;
case 'p': returnValue = P; break;
case 'Q': returnValue = Q; break;
case 'q': returnValue = Q; break;
case 'R': returnValue = R; break;
case 'r': returnValue = R; break;
case 'S': returnValue = S; break;
case 's': returnValue = S; break;
case 'T': returnValue = T; break;
case 't': returnValue = T; break;
case 'U': returnValue = U; break;
case 'u': returnValue = U; break;
case 'V': returnValue = V; break;
case 'v': returnValue = V; break;
case 'W': returnValue = W; break;
case 'w': returnValue = W; break;
case 'X': returnValue = X; break;
case 'x': returnValue = X; break;
case 'Y': returnValue = Y; break;
case 'y': returnValue = Y; break;
case 'Z': returnValue = Z; break;
case 'z': returnValue = Z; break;
case ' ': returnValue = _; break;
case '3': returnValue = A3; break;
case '<': returnValue = TEMP; break; case '*': returnValue = FULL; break; case '': returnValue = LINE; break; case '_': returnValue = _; break; case ':': returnValue = COL; break; case '-': returnValue = DASH; break; case ')': returnValue = BRA2; break; case '%': returnValue = SMILE; break; case '.': returnValue = DOT; break; case '^': returnValue = COLDOT; break; } return returnValue; } void kbd_init() { char ack; kbd.write(0xff); // send reset code ack = kbd.read(); // byte, kbd does self test ack = kbd.read(); // another ack when self test is done } void setup() { Serial.begin(9600); kbd_init(); code = kbd.read(); for(int i = 0; i <8; code =" kbd.read();" ps2keyboard_release =" true;" ps2keyboard_extend =" false;" cmd_ack_byte_ok =" true;" ps2keyboard_extend =" true;" ps2keyboard_shift =" ps2Keyboard_release?" ps2keyboard_release =" false;" ps2keyboard_alt =" ps2Keyboard_release?" ps2keyboard_release =" false;" ps2keyboard_ctrl =" ps2Keyboard_release?" ps2keyboard_release =" false;" ps2keyboard_caps_lock =" ps2Keyboard_caps_lock?" ps2keyboard_release =" false;" ps2keyboard_release =" false;" ps2keyboard_charbuffer =" code;" i ="0;" currentchar =" getChar(requestString[index]);" nextchar =" getChar(requestString[index+1]);" row="0;" column="0;">> (8-offset) )); //loads the next charachter offset by offset pixels
}
}
offset++; //increment the offset by one row
if(offset==8){offset = 0; index++; if(index==sizeof(requestString)-2){index=0;}} //if offset is 8 load the next charachter pair for the next time through
}

void showSprite(int speed2){
for(int iii = 0; iii < column =" 0;" i =" 0;" i =" 0;" i ="=" row =" 0;" bit =" (data[column]">> row) & 1;
if(bit == 1){
digitalWrite(rowA[row], HIGH); //if the bit in the data array is set turn the LED on
}

}
delayMicroseconds(pauseDelay); //leave the column on for pauseDelay microseconds (too high a delay causes flicker)
}
}

Thursday, May 6, 2010

Task 53 - Fill the total eeprom with $AB's (171)




This program fills the EEPROM with Hex $AB or Decimal 171 and displays it on serial screen.


#include

int a = 0;
int value;

void setup()
{
Serial.begin(9600);
for (int i = 0; i < 512; i++)
EEPROM.write(i, 171);


}

void loop()
{
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 512)
a = 0;

delay(500);
}

Task 52 - Writting to EEPROM




The program writes $23(35) to address 01 and $2A(42) to address 02 and displays them to the screen.

#include

int a = 0;
int value;

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

EEPROM.write(1, 35);
EEPROM.write(2, 42);

}

void loop()
{
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 512)
a = 0;

delay(500);
}

Task 51 - EEPROM


This program prints all values to the screen as FF (255) except the first byte in EEPROM which showed 69 (105).

#include

int a = 0;
int value;

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

void loop()
{
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 512)
a = 0;

delay(10);
}

Thursday, April 29, 2010

Task 50 - How fast can you send a thousand 1/0 pulses and still count them accurately.

The most accuarate count we could get is half a second otherwise it would not display it accuarately.

Task 49 - series of pulses, a 100, about 1ms long, to the other.

I also did this task with BJ. On my arduino the code i used was:

int reciever = 2;
int LED = 13;
int count = 0;

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

void loop(){
if (digitalRead(reciever)==1){
count++;
Serial.println(count);

}
else{
}
delay(500);
}

BJ's code was:

void loop()
{
while (count < 1000){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
if(digitalRead(2)==1){
Serial.println('H');
}
count++;
}

}

This counts the incoming signal on my arduino when it is equal to 1 (high).

Task 48 - receiving and sending a copy back for checking.

I was working with BJ on this. On my arduino I had the following code:

int reciever = 2;
int LED = 13;

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

void loop(){
//val = digitalRead(reciever);
if (digitalRead(reciever)==1){
Serial.println("H");
digitalWrite(LED,HIGH);
}
else{
digitalWrite(LED,LOW);
Serial.println("L");
}
delay(500);
}

on BJ's arduino, he had the following code:

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

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

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
if(digitalRead(2)==1){
Serial.println('H');
}
else{
Serial.println('L');
}
digitalWrite(ledPin, LOW);
delay(1000);
if(digitalRead(2)==1){
Serial.println('H');
}
else{
Serial.println('L');
}
}

When blink goes on BJ's arduino it sends a signal to my arduino that outputs high or low to the screen, depending if it is a one or two. It then sends it back to BJ's arduino and does the same thing and outputs high or low to the screen.

Monday, April 26, 2010

47- reverse roles

For this, we just swapped the roles of what the arduinos were doing. BJ had blink going, while I had his previous code on my Arduino. Then the same principles were applied as task 46.

Task 46 - Sending a signal from one Arduino to another

I paired up with BJ to get one signal from one arduino to the other. BJ had the following code on his arduino:

BJ Smid*/

int reciever = 2;
int LED = 13;

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

void loop(){
//val = digitalRead(reciever);
if (digitalRead(reciever)==1){
Serial.println("H");
digitalWrite(LED,HIGH);
}
else{
digitalWrite(LED,LOW);
Serial.println("L");
}
delay(500);
}


I just had blink programmed on my arduino. This allowed my arduino to pass over a signal to BJ's arduino telling it whether or not my LED was blinking. If it was lit up, the arduino would send a signal telling BJ's arduino to light up an LED, otherwise it would send a signal to make sure it was off. BJ's arduino would also output to the screen whether it was high(lit up) or low(off).

Task 45 - infrared transmitter sends pulses to the receiver.

I have had a bit a trouble getting this to work outside of class, however I have been able to get this working in class using the blink exampler. I have the transmitter pluged into pin 13 and ground and that sends pulses to the reciever, which is in series with an led. These were also grounded and have 3v3 to power them. This then makes the led to blink on and off.

Monday, March 22, 2010

Task 43 - Project Websites


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

This website has some great projects such as the gameboy.



http://www.coolcircuit.com/gadgets/category/arduino/

This website also has some amazing products such as the wireless harp, I think it would be wicked to make something like that.




http://missionduke.com/arduino-projects/

This website has a great project with Itunes and the Arduino, however I don't like apple therefore I don't use Itunes, however something could made similar with Windows Media Player.




http://www.instructables.com/

This website has step by step guides into making some of the projects, however you have to register to access some things.


Task 42 - Rules on YABB

- No False Material
- No abusive , harassing behaviour
- No inaccurate material
- No hateful / threatening language towards other
- Treat everyone with respect
- Be polite

Task 41 - Register to YABB


Thursday, March 18, 2010

Task 40 - Article from YABB



This article was quite interesting. It is about a music LED visualizer which outputs different lights, when a song is being played. I was thinking about doing something similar for my major project, however it is a little confusing on how it is done. I will need to read up on it further.

Task 39 - Same As Task 38 With Different Output

//Program to output the value of your LDR whenever you press the button.

int buttonPin = 2; // the number of the pushbutton pin
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int buttonState = 0; // variable for reading the pushbutton status
int count = 1;

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

void loop(){

photocellReading = analogRead(photocellPin);
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
Serial.print("Reading number ");
Serial.print(count);
Serial.print(": ");
Serial.println(photocellReading);
delay(500);
count++;
}
else {
buttonState == LOW;
}
}

Task 38 - Program to output the value of your LDR whenever you press the button.

//Program to output the value of your LDR whenever you press the button.

int buttonPin = 2; // the number of the pushbutton pin
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int buttonState = 0; // variable for reading the pushbutton status

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

void loop(){

photocellReading = analogRead(photocellPin);
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
Serial.print("Analog reading = ");
Serial.println(photocellReading);
delay(500);
}
else {
buttonState == LOW;
}
}

Sunday, March 14, 2010

Task 37 - Baud Rate

I have found with using the code from task 36, I could increase the baud rate upto 28800 before it started to become scrambled on the screen. The least amount of baud rate I could use was 9600, if I used anything less, the words became scrambled or wouldn't show anything on the screen.

Friday, March 12, 2010

Task 36 - Random Numbers with Mean

// Adam Randall - Random Numbers Program, generates 100 random numbers between 1 and 10 and display mean.

long randNumber;
int total;
int mean;

void setup(){
total =0;
mean =0;
Serial.begin(9600);
randomSeed(analogRead(0));
for (int i=0; i<100; i++){
randNumber = random(0, 10);
Serial.print(i);
Serial.print(": ");
Serial.println(randNumber);
total = total + randNumber;
delay(500);
}
mean = (total/100);
Serial.println ("The Mean is: ");
Serial.print(mean);
}

void loop() {
}

Task 35 - Random Numbers with numbers in front

// Adam Randall - Random Numbers Program, generates 100 random numbers between 1 and 10

long randNumber;

void setup(){
Serial.begin(9600);
randomSeed(analogRead(0));
for (int i=0; i<100; i++){
randNumber = random(0, 10);
Serial.print(i);
Serial.print(": ");
Serial.println(randNumber);
delay(500);
}
}

void loop() {
}

Thursday, March 11, 2010

Task 34 - Random Numbers

// Adam Randall - Random Numbers Program, generates 100 random numbers between 1 and 10

long randNumber;

void setup(){
Serial.begin(9600);
randomSeed(analogRead(0));
for (int i=0; i<100; i++){
randNumber = random(0, 10);
Serial.println(randNumber);
delay(500);
}
}

void loop() {
}

Sunday, March 7, 2010

Task 29 - Resources

http://http//webzone.k3.mah.se/projects/arduino-workshop/projects/arduino_meets_processing/instructions/index.html

This website has some great arduino projects and has pictures of the arduino setup and the circuit board, so the user can create it.


http://http//www.practicalarduino.com/news/id/461

The above link is to website about an Arduino book called: Pratical Arduino. Looks like it would be a good book to own to make some interesting projects with.


http://http://falconphysics.blogspot.com/2009/01/arduino-in-high-school-electronics.html

This website is a techers blog about teaching and using the arduinos. It seems like a very cool idea and I wish this happened in my highschool. Even the video of the robot is cool.

Friday, March 5, 2010

LED Project - Assignment 1




// Melody by Adam Randall
// This is a program designed to output LED's when notes are played
// through a speaker. Below is the code used.

int speakerPin = 12; // output Speaker
int led1 = 9; // output LED1
int led2 = 8; // output LED2
int led3 = 7; // output LED3
int led4 = 6; // output LED4
int led5 = 5; // output LED5
int led6 = 4; // output LED6

int length = 24; // the number of notes
char notes[] = "ggcGfcg ggcGfcg bcAcAbA "; // a space represents a rest
int beats[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int tempo = 300;

void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH); // speaker on
delayMicroseconds(tone); // delay
digitalWrite(speakerPin, LOW); // spaker off
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) {
char names[] = {'d', 'e', 'f', 'g', 'a', 'b', 'c', 'G', 'A'}; // notes
int tones[] = {587, 659, 698, 784, 880, 988, 1047, 831, 932 }; // frequency

if (note == 'c') {
digitalWrite (led1, HIGH); // LED1 on
delay (50); //delay
digitalWrite (led1, LOW); // LED1 off
}
else if (note == 'g') {
digitalWrite (led2, HIGH); // LED2 on
delay (50); //delay
digitalWrite (led2, LOW); // LED2 off
}
else if (note == 'G') {
digitalWrite (led3, HIGH); // LED3 on
delay (50); //delay
digitalWrite (led3, LOW); // LED3 off
}
else if (note == 'b') {
digitalWrite (led4, HIGH); // LED4 on
delay (50); //delay
digitalWrite (led4, LOW); // LED4 off
}
else if (note == 'A') {
digitalWrite (led5, HIGH); // LED5 on
delay (50); //delay
digitalWrite (led5, LOW); // LED5 off
}
else if (note == 'f') {
digitalWrite (led6, HIGH); // LED6 on
delay (50); //delay
digitalWrite (led6, LOW); // LED6 off
}

// play the tone corresponding to the note name
for (int i = 0; i < 20; i++) {
if (names[i] == note) {

playTone(tones[i], duration);
}
}
}

void setup() {
pinMode(speakerPin, OUTPUT);
}

void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}

// pause between notes
delay(tempo / 2);
}
}



Below is a video of th assignment at work:

video

Task 32 - Push Button Project + Serial output stating the condition of LED and Button.

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 on:
digitalWrite(ledPin, HIGH);
Serial.println("Button Pressed, LED on");//
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println("Button Pressed, LED off");
}
}

Task 31 - Reversed Push Button Project

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);
}
}

Thursday, March 4, 2010

Task 30 - Push Button Project

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);
}
}

Key Words Glossary

setup() - Used to initialised varibles as the start of a program eg pinMode(buttonPin, INPUT);

loop() - Loops anything you state on the board eg void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');

delay(1000);
}


digitalWrite - DigitalWrite is used to output something such as an LED as HIGH (on) or LOW (off) eg digitalWrite(ledPin, HIGH);

analogRead()- Reads the value from the specified analog pin eg int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read

void setup()
{
Serial.begin(9600); // setup serial
}

void loop()
{
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}


Serial.print()- Prints data to the serial port as human-readable ASCII text. eg •Serial.print("Hello world.") gives "Hello world."

Serial.println()- Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). eg Serial.println("Hello world.") followed by a new line

pinMode()- Configures the specified pin to behave either as an input or an output. eg pinMode(ledPin, OUTPUT); // sets the digital pin as output


digitalRead() - Reads the value from a specified digital pin, either HIGH or LOW. eg
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}

void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}

Sunday, February 28, 2010

Task 23 - Sanguino

http://http//sanguino.cc/

The Sanguino is like an Arduino but has a more powerful microprossesor allowing it to be used in more ways but it is still usable with the Arduino software.

Task 28 - program to turn a LED on whenever the light is blocked to your LED

int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;
int ledPin = 7;
// the analog reading from the analog resistor divider

void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop(void) {
photocellReading = analogRead(photocellPin);

Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading

// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
digitalWrite(ledPin, HIGH); // LED on
} else if (photocellReading < 200) {
Serial.println(" - Dim");
digitalWrite(ledPin, HIGH); // LED on
} else if (photocellReading < 500) {
Serial.println(" - Light");
digitalWrite(ledPin, LOW); // LED off
} else if (photocellReading < 800) {
Serial.println(" - Bright");
digitalWrite(ledPin, LOW); // LED off
} else {
Serial.println(" - Very bright");
digitalWrite(ledPin, LOW); // LED off
}
delay(1000);
}

Task 27

I didn't make any changes as I felt that it was fine as it was. The only thing that I may change is when it is dark, light, dim etc to a different number, so it is picked up faster / slower.

Task 26 - Ladayada Photocell Program

When creating the ladayada photocell program i used one 1k resistor and an LDR. I connected the cable from 5V, 0 and ground to the breadboard from the input section of the Arduino. I then connected the resistor to ground and the 0 point and connected the LDR to the ground and 5V. This then enabled me to run it after using the below code:



int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading;
// the analog reading from the analog resistor divider

void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
}

void loop(void) {
photocellReading = analogRead(photocellPin);

Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading

// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
delay(1000);
}

Task 24

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

This website was very interesting and had some great diagrams on how to use the Arduino.

Thursday, February 25, 2010

Task 22 - program: two leds of different colours and output the colour of the led to the screen each time it goes on.

//program: two leds of different colours and output the colour of the led to the screen each time it goes on.
// by Adam Randall

int ledPin = 12;
int greenLedPin = 13;

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


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


void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
digitalWrite(greenLedPin, LOW); // set the LED off
Serial.println("Yellow");// shows the word yellow on screen
delay(200);
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(greenLedPin, HIGH); // set the LED on
Serial.println("Green");// shows the word green on screen
delay(200);


}

Task 21 - program to output one led blinking at rate of 200ms that outputs the word "blink" to the screen each time it comes on.

//program to output one led blinking at rate of 200ms that outputs the word "blink" to the screen each time it comes on.
// by Adam Randall

int ledPin = 12;

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


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


void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(200);
Serial.println("blink"); // shows the work blink on screen
digitalWrite(ledPin, LOW); // set the LED off
delay(200);


}

Task 20 - blinking from 100ms to 1 sec back to 100ms.

//for-loop with counter variable i.
//program to get one led to increase its rate of blinking from 100ms to 1sec back to 100ms.
//Repeating forever.
// by Adam Randall

int redLedPin = 12; // LED connected to digital pin 12
int i = 100;
int x = 100;
// The setup() method runs once, when the sketch starts


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


void loop()
{
for (i=100; i<1000; i=i+100)// for loop counter increasing i by 50
{
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(i);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(i);//delay
}
x=1000; //resets x back to 1000
for (x=1000; x>100; x=x-100)
{
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(x);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(x);//delay
}
i=100; //resets i back to 100
}

Task 19 - program to get one led to increase its rate of blinking from 100ms to1sec.

//for-loop with counter variable i.
//program to get one led to increase its rate of blinking from 100ms to 1sec.
//Repeating forever.
// by Adam Randall


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 12
int i = 100;
// The setup() method runs once, when the sketch starts


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


void loop()
{
for (i=100; i<1000; i=i+50){ // for loop counter increasing i by 50
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(i);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(i);//delay
}
i=100; //resets i back to 100
}


}

Task 18 - Like 17 but i can be any value. Try different ones. Later we can input this value from the keyboard.

//for-loop with counter variable i.
//It will get one led to blink 20 (different value) times, using the for-loop, then the other to blink once.
//Repeating forever.
// by Adam Randall


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 12
int del =50;
int i = 0;
// The setup() method runs once, when the sketch starts


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


void loop()
{
for (i=1; i<20; i++){ // for loop counter
digitalWrite(ledPin, LOW); //sets the pin to off
delay(del); //delay
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(del);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(del);//delay
}
digitalWrite(ledPin, HIGH);//sets the pin to on
delay(del);//delay

}

Task 17 - for-loop with counter variable i. Get one led to blink 5 times, using the for-loop, then the other to blink once. Repeat forever.

//for-loop with counter variable i.
//It will get one led to blink 5 times, using the for-loop, then the other to blink once.
//Repeating forever.
// by Adam Randall


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 12
int del =100;
int i = 0;
// The setup() method runs once, when the sketch starts


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


void loop()
{
for (i=1; i<6; i++){ // for loop counter
digitalWrite(ledPin, LOW); //sets the pin to off
delay(del); //delay
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(del);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(del);//delay
}
digitalWrite(ledPin, HIGH);//sets the pin to on
delay(del);//delay

}

Sunday, February 21, 2010

Task 14 - One LED mostly off the other LED has a slight flash.

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


// 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);
digitalWrite(redLedPin, HIGH);
delay(del);
digitalWrite(ledPin, LOW);
digitalWrite(redLedPin, HIGH);
delay(del);
digitalWrite(ledPin, LOW);
digitalWrite(redLedPin, HIGH);
delay(del);
digitalWrite(ledPin, LOW);
digitalWrite(redLedPin, HIGH);
delay(del);
digitalWrite(ledPin, LOW);
digitalWrite(redLedPin, HIGH);
delay(del);
digitalWrite(ledPin, HIGH);
digitalWrite(redLedPin, LOW);
delay(del);

}

Task 13 - One LED mostly on the other LED has a slight flash.

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


// 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);
digitalWrite(redLedPin, LOW);
delay(del);
digitalWrite(ledPin, HIGH);
digitalWrite(redLedPin, LOW);
delay(del);
digitalWrite(ledPin, HIGH);
digitalWrite(redLedPin, LOW);
delay(del);
digitalWrite(ledPin, HIGH);
digitalWrite(redLedPin, LOW);
delay(del);
digitalWrite(ledPin, HIGH);
digitalWrite(redLedPin, LOW);
delay(del);
digitalWrite(ledPin, LOW);
digitalWrite(redLedPin, HIGH);
delay(del);

}

Task 16 - One LED Blinks Twice, The Other Blinks Once coding

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


// 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, LOW);// set the LED off
delay(del);// wait for a second
digitalWrite(ledPin, HIGH); // set the LED on
digitalWrite(redLedPin, LOW);// set the LED off
delay(del);// wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, LOW);// set the LED off
delay(del);// wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, HIGH);// set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, LOW);// set the LED off
delay(del);// wait for a second

}

Task 11 - Blink 2 coding

int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12;
int ledPin2 = 11; // LED connected to digital pin 13
int del =200;


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


}

Friday, February 19, 2010

Arduino Wireless Reviews - Youtube

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

I thought this was quite a cool idea. It is an Arduino wirelessly display letters rotating round. Although it is not smooth, going by some of the comments this can be arranged. This has also helped giving me ideas in what I should make when coming to the projects.


http://www.youtube.com/watch?v=Qc6DKDFwg9c

Rumble robots is such a cool idea and at some stage I would love to make my arduino into something similar to this. Check it out!


http://www.youtube.com/watch?v=4t-WHWAsyk0

This youtube video is about overclocking an arduino, it is overclocked to 16 mhz and 32 mhz and is running the blink program. It is quite cool and you can clearly see the difference between them.

http://www.youtube.com/watch?v=hQhV601jIpg

Here is another link to another arduiono project that would be cool to make. It is a midi interface program using the arduino. I think bringing music and the arduino together will be quite cool!

LED Pixel Matrix Project Review

http://www.youtube.com/watch?v=hEKEM6ZOsZE

I just watched the LED Pixel Matrix Project. I thought this was quite a good design. It has some real character with the space invader and the different coloured lights and I thought it was quite practical that it could tell the time and what the temperature was. I think if it could get the time on one line instead of two, it would complete the project.

Task 10 - Arduino LED blinking

I found the cut off time for me to see the LED light blinking was about 11ms on and off, when I had it on 10ms, it seemed to me that it wasn't flashing at all. The code below is what I used to have the LED blinking:

int ledPin = 13;

void setup () {
pinMode (ledPin, OUTPUT);
}

void loop () {
digitalWrite (ledPin, HIGH);
delay (11);
digitalWrite (ledPin, Low);
delay (11);
}

PeerWise

From what I have found Peer-Wise is a tool supporting students to create multi-choice questions with answers and explanations.

Open Office

Open office is free software similar to microsoft word etc.

Fritzing

Fritzing is a tool for making prototypes for Arduinos. Should be interested tool to use when making bigger projects.

Chip8

Chip8 is a programming language making games easier to programme. Should be interesting to see if it will work on the Arduino.

Moodle

Moodle appears to be an elearning website, not sure what it is all about.

Wikieducator

Wikieducator appears to be an easy access website to find out information on all sorts of things, a bit like google.

GNU - GCC

I found accessing this website a bit confusing to get around. It appears to have information about GCC a compiler for the GNU operating system.

Processing Environment

The Processing website is similar to the Arduino website in what it offers. It should also be helpful and handy when programming.

Thursday, February 18, 2010

Task 9 - LED mostly on

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(100);
}

Task 8 - Blink mostly off

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(100);
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}

Tuesday, February 16, 2010


Arduino Enviroment

I have recenetly checked out the Arduino Enviroment at http://www.arduino.cc/. It looks like a good website to use in conjunction with the Arudino board and has a lot of helpful references and tips.

Monday, February 15, 2010

Task 1 - 7

These task have all been done, however nothing to display for it in blog. I do however have you-tube videos under general names, where I am unable to change the task name.