Project tutorial

Retro Nokia Snake Game with Arduino © GPL3+

Ever wish you could go back to the happy 90's and play snake on your old Nokia phone? Grab on to your joystick for this blast-from-the-past.

  • 3,572 views
  • 2 comments
  • 25 respects

Components and supplies

Apps and online services

About this project

Super Mario, Tetris, Pac-Man - don't you wish you could go back in time to enjoy sitting hours in front of a black screen with minimal resolution and play these wonderful and so-addictive games?

Well, after we added the Nokia screen to circuito.io, this build was inevitable. We are proud to present our latest creation - the Nokia Snake game wrapped in an Arduino box!

The Electronics

For this very awesome project you will need:

  • An old Nokia 5110 screen
  • An Arduino Uno
  • A Piezo Speaker
  • Joystick
  • Push button
  • Switch (which we don't have on circuito.io yet, but you can wire it directly to the battery in order to turn the game on and off)
  • And a Lithium Battery

Assembling the electric circuit is quite simple.

In this magic link to circuito.io, we've already pre-selected all the parts you need for the project. You can, of course, add additional components if you want. Once you've selected everything you need, click on generate.

Your circuito.io Reply

Your circuito reply has 4 sections:

1. BoM - A list of all the components you'll need for the project. You may be wondering why new components have "popped-up" on this list, although you haven't selected them. Well, these parts are necessary for your project just like the core parts you chose, and they are automatically added to your list of parts after being calculated by our smart-smart engine. Pretty neat, huh?

2. Step-by-step wiring guide - This is the fun part. After placing all the components on your breadboard, you can start hooking them up to one another and to the Arduino. Just follow the wizard, step-by-step, it's that easy! Make sure to read the comments that pop-up on the left side bar, as they may be very helpful.

3. Code - In this section you have a sample code that is automatically generated to integrate between all the components you chose. This code will help you test that you assembled the circuit correctly.

Follow the steps below, that also appear in the circuito.io reply:

4. Test - After you upload the code to your board, you can test it.

All the steps for specifically testing the components you used, are outlined in the "test" section of your circuito.io reply.

Once everything is set up correctly, you can wave goodbye to your circuito.io reply, till next time.

Modify the code

So everything in your circuit and code looks great. It's time to take the custom code we made especially for the Snake project.

1. Open the firmware.ino file, that includes all the libraries from the circuito.io reply.

2. In the firmware tab, keep the // Include Libraries and // Pin Definitions

3. Replace the rest of the code in the firmware tab, with the code below:

#include <EEPROM.h> 
// Global variables and defines 
//define Nokia LCD contrast and dimentions(in pixels) 
#define LCD_CONTRAST 70 
#define LCD_SIZE_COL 84 
#define LCD_SIZE_ROW 48 
bool dl = false, dr = false, du = false, dd = false; // to check in which direction the snake is currently moving 
uint8_t x[200], y[200], i, slength, tempx = 10, tempy = 10, xx, yy; 
unsigned int high; 
uint8_t bh, bl; 
uint8_t xegg, yegg; 
int freq, tb; 
bool l, r, u, d, p; 
unsigned long time = 280, beeptime = 50; 
int score = 0, flag = 0; 
#include <EEPROM.h> 
// object initialization 
Adafruit_PCD8544 nokiaLcd(NOKIALCD_PIN_DC, NOKIALCD_PIN_CS, NOKIALCD_PIN_RST); 
Button pushButton(PUSHBUTTON_PIN_1); 
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. 
void setup() 
{ 
 //Serial.begin(9600); 
 pinMode(JOYSTICKPSP_PIN_X, INPUT); 
 pinMode(JOYSTICKPSP_PIN_Y, INPUT); 
 //Initialize Nokia instance 
 nokiaLcd.begin(LCD_SIZE_COL, LCD_SIZE_ROW); 
 nokiaLcd.clearDisplay(); 
 nokiaLcd.setContrast(LCD_CONTRAST); //Adjust display contrast 
 pushButton.init(); 
 slength = 8;               //Start with snake length 8 
 xegg = (nokiaLcd.width()) / 2; 
 yegg = (nokiaLcd.height()) / 2; 
 nokiaLcd.setTextSize(2);          //Initial nokiaLcd 
 nokiaLcd.setTextColor(BLACK); 
 nokiaLcd.setCursor(10, 15); 
 nokiaLcd.setCursor(10, 40); 
 nokiaLcd.display(); 
 delay(4000); 
 nokiaLcd.clearDisplay(); 
 for (i = 0; i <= slength; i++) //Set starting coordinates of snake 
 { 
   x[i] = 25 - 3 * i; 
   y[i] = 10; 
 } 
 for (i = 0; i < slength; i++)  //Draw the snake 
 { 
   nokiaLcd.drawCircle(x[i], y[i], 1, BLACK); 
 } 
 nokiaLcd.display(); 
 dr = true;  //Going to move right initially 
} 
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. 
void loop() 
{ 
 movesnake();    //This is called endlessly 
} 
void movesnake() 
{ 
 int X_val = analogRead(JOYSTICKPSP_PIN_X); 
 int Y_val = analogRead(JOYSTICKPSP_PIN_Y); 
 l = X_val < 400 ? 1 : 0; 
 d = X_val > 650 ? 1 : 0; 
 r = Y_val < 400 ? 1 : 0;; 
 u = Y_val >= 650 ? 1 : 0; 
 p = pushButton.onPress(); 
if (p == HIGH)            //Pause game for 5 seconds 
 { 
   nokiaLcd.clearDisplay(); 
   nokiaLcd.setTextColor(BLACK); 
   nokiaLcd.setCursor(25, 10); 
   nokiaLcd.setTextSize(1); 
   nokiaLcd.print("Pause"); 
   nokiaLcd.display(); 
   delay(1000); 
   while (!pushButton.onPress()); 
   nokiaLcd.clearDisplay(); 
   redraw();          //Redraw the snake and egg at the same position as it was 
 } 
 if (millis() % time == 0) //this condition becomes true after every 'time' milliseconds...millis() returns the time since launch of program 
 { 
 direct(); 
   if (flag == 0)                                //flag 0 means no directional key has been pressed in the last 'time' milliseconds 
   { 
     if (dr == true) { 
       tempx = x[0] + 3;  // so the snake moves one step in the direction it is moving currently 
       tempy = y[0]; 
     } 
     if (dl == true) { 
       tempx = x[0] - 3;  //The new coordinates of head of snake goes in tempx,tempy 
       tempy = y[0]; 
     } 
     if (du == true) { 
       tempy = y[0] - 3; 
       tempx = x[0]; 
     } 
     if (dd == true) { 
       tempy = y[0] + 3; 
       tempx = x[0]; 
     } 
   } 
   flag = 0; 
   checkgame();                              //Check if snake has met egg or coincided with itself 
   checkegg(); 
   if (tempx <= 0) { 
     tempx = 84 + tempx; //If the new coordinates are out of screen, set them accordingly 
   } 
   else if (tempx >= 84) { 
     tempx = tempx - 84; 
   } 
   if (tempy <= 0) { 
     tempy = 48 + tempy; 
   } 
   else if (tempy >= 48) { 
     tempy = tempy - 48; 
   } 
   for (i = 0; i <= slength; i++) //Change the coordinates of all points of snake 
   { 
     xx = x[i]; 
     yy = y[i]; 
     x[i] = tempx; 
     y[i] = tempy; 
     tempx = xx; 
     tempy = yy; 
   } 
   drawsnake();           //Draw the snake and egg at the new coordinates 
 } 
} 
void checkgame()       //Game over checker 
{ 
 for (i = 1; i < slength; i++)        //Checking if the coordinates of head have become equal to one of the non head points of snake 
 { 
   if (x[i] == x[0] && y[i] == y[0]) 
   { 
     bh = EEPROM.read(1); 
     bl = EEPROM.read(0); 
     high = (((0xff00 + bh) << 8) + bl); 
     if (score > high) 
     { 
       high = score; 
       bh = (high >> 8); 
       bl = high & 0xff; 
       EEPROM.write(1, bh); 
       EEPROM.write(0, bl); 
     } 
     nokiaLcd.clearDisplay(); 
     nokiaLcd.setTextColor(BLACK); 
     nokiaLcd.setTextSize(1); 
     nokiaLcd.setCursor(20, 12); 
     nokiaLcd.print("Game Over"); 
     nokiaLcd.setCursor(15, 30); 
     nokiaLcd.print("Score: "); 
     nokiaLcd.print(score); 
     nokiaLcd.setCursor(15, 40); 
     nokiaLcd.print("High: "); 
     nokiaLcd.print(high); 
     nokiaLcd.display(); 
     beep(20, 5000); 
     nokiaLcd.clearDisplay(); 
     slength = 8;            //Resetting the values 
     score = 0; 
     time = 280; 
     redraw();              //Restart game by drawing snake with the resetted length and score 
   } 
 } 
} 
void checkegg()      //Snake meets egg 
{ 
 if (x[0] == xegg or x[0] == (xegg + 1) or x[0] == (xegg + 2) or x[0] == (xegg - 1)) //Snake in close vicinity of egg 
 { 
   if (y[0] == yegg or y[0] == (yegg + 1) or y[0] == (yegg + 2) or y[0] == (yegg - 1)) 
   { 
     score += 1;                     //Increase length,score and increase movement speed by decreasing 'time' 
     slength += 1; 
     if (time >= 90) 
     { 
       time -= 5; 
     } 
     nokiaLcd.fillRect(xegg, yegg, 3, 3, WHITE);  //Delete the consumed egg 
     nokiaLcd.display(); 
     beep(35, beeptime);             //Beep with a sound of 35Hz for 'beeptime' ms 
     xegg = random(1, 80);           //Create New egg randomly 
     yegg = random(1, 40); 
   } 
 } 
} 
void direct()                  //Check if user pressed any keys and change direction if so 
{ 
 if (l == HIGH and dr == false)  //when key LEFT is pressed ,L will become low 
 { 
   dl = true; du = false; dd = false; 
   tempx = x[0] - 3;            //Save the new coordinates of head in tempx,tempy 
   tempy = y[0]; 
   flag = 1;                   //Do not change direction any further for the ongoing 'time' milliseconds 
 } 
 else if (r == HIGH and dl == false) 
 { 
   dr = true; du = false; dd = false; 
   tempx = x[0] + 3; 
   tempy = y[0]; 
   flag = 1; 
 } 
 else if (u == HIGH and dd == false) 
 { 
   du = true; dl = false; dr = false; 
   tempy = y[0] - 3; 
   tempx = x[0]; 
   flag = 1; 
 } 
 else if (d == HIGH and du == false) 
 { 
   dd = true; dl = false; dr = false; 
   tempy = y[0] + 3; 
   tempx = x[0]; 
   flag = 1; 
 } 
 else if (p == HIGH)            //Pause game for 5 seconds 
 { 
   nokiaLcd.clearDisplay(); 
   nokiaLcd.setTextColor(BLACK); 
   nokiaLcd.setCursor(25, 10); 
   nokiaLcd.setTextSize(1); 
   nokiaLcd.print("Pause"); 
   nokiaLcd.display(); 
   delay(1000); 
   while (!pushButton.onPress()); 
   nokiaLcd.clearDisplay(); 
   redraw();          //Redraw the snake and egg at the same position as it was 
 } 
} 
void drawsnake()        //Draw snake and egg at newly changed positions 
{ 
 nokiaLcd.fillRect(xegg, yegg, 3, 3, BLACK);   //Draw egg at new pos 
 nokiaLcd.drawCircle(x[0], y[0], 1, BLACK);    //Draw new head of snake 
 nokiaLcd.drawCircle(x[slength], y[slength], 1, WHITE); //Delete old tail of snake 
 nokiaLcd.display(); 
} 
void redraw()   //Redraw ALL POINTS of snake and egg 
{ 
 nokiaLcd.fillRect(xegg, yegg, 3, 3, BLACK); 
 for (i = 0; i < slength; i++) 
 { 
   nokiaLcd.drawCircle(x[i], y[i], 1, BLACK); 
 } 
 nokiaLcd.display(); 
} 
void beep (int freq, long tb)          //This function creates a sound of frequency 'freq' Hz and for a duration of 'tb' milliseconds 
{ 
 int x; 
 long delayAmount = (long)(500 / freq);     //Calculate time duration of half cycle 
 long loopTime = (long)(tb / (delayAmount * 2)); //Calculate no. of cycles 
 for (x = 0; x < loopTime; x++) // One iteration produces sound for one cycle 
 { 
   digitalWrite(PIEZOSPEAKER_PIN_SIG, HIGH);  //High for half cycle 
   delay(delayAmount); 
   digitalWrite(PIEZOSPEAKER_PIN_SIG, LOW);   //Low for half cycle 
   delay(delayAmount); 
 } 
 delay(2); 
 //a little delay to make all notes sound separate 
}  

Upload the code to your Arduino, and you should be set.

Boxing

We thought is would be cool to put our creation inside an Arduino box, so we cut it out nicely, so that the button, switch, joystick and screen are showing, but the board is underneath, and that's basically it!

Code

Code for Snake GameArduino
The code for this project is based on https://www.youtube.com/watch?v=-4qY7JBhQpY.
Super Mario, Tetris, Pac-Man - don't you wish you could go back in time to enjoy sitting hours in front of a black screen with minimal resolution and play these wonderful yet addictive games? Well, after we added the Nokia 3310 screen to circuito.io, this build was inevitable. We are proud to present our latest creation - the Nokia Snake game wrapped in an Arduino box!
2.jpg
Snake Game Wrapped in Arduino
The Electronics
For this very awesome project you will need:
- An old Nokia 5110 screen 
- An Arduino Uno
- A Piezo Speaker
- Joystick
- Push button
- Switch
- And a Lithium Battery
Assembling the electric circuit is quite simple.
In this magic link to circuito.io, we've already pre-selected all the parts you need for the project. You can, of course, add additional components if you want. Once you've selected everything you need, click on generate. 
Your circuito.io Reply
Your circuito reply has 4 parts:
1. BoM - A list of all the components you'll need for the project. 
You may be wondering why new components have "popped-up" on this list, although you haven't selected them. Well, these parts are necessary for your project just like the core parts you chose, and they are automatically added to your list of parts after being calculated by our smart-smart engine. Pretty neat, huh?
2. Step-by-step wiring guide
This is the fun part. After placing all the components on your breadboard, you can start hooking them up to one another and to the Arduino. Just follow the wizard, step-by-step, it's that easy! Make sure to read the comments that pop-up on the left side bar, as they may be very helpful.
3. Code
In this section you have a sample code that is automatically generated to integrate between all the components you chose. This code will help you test that you assembled the circuit correctly. 
Follow the steps below, that also appear in the circuito.io reply:
image.png
How to work with the code from circuito.io

4. Test
After you upload the code to your board, you can test it.
All the steps for specifically testing the components you used, are outlined in the "test" section of your circuito.io reply.
Once everything is set up correctly, you can wave goodbye to your circuito.io reply, till next time.
Modify the code
So everything in your circuit and code looks great. It's time to take the custom code we made especially for the Snake project.
1. Open the firmware.ino file, that includes all the libraries from the circuito.io reply.
2. In the firmware tab, keep the // Include Libraries and // Pin Definitions 
3. Replace the rest of the code in the firmware tab, with the code below:
#include <EEPROM.h> 
// Global variables and defines 
//define Nokia LCD contrast and dimentions(in pixels) 
#define LCD_CONTRAST 70 
#define LCD_SIZE_COL 84 
#define LCD_SIZE_ROW 48 
bool dl = false, dr = false, du = false, dd = false; // to check in which direction the snake is currently moving 
uint8_t x[200], y[200], i, slength, tempx = 10, tempy = 10, xx, yy; 
unsigned int high; 
uint8_t bh, bl; 
uint8_t xegg, yegg; 
int freq, tb; 
bool l, r, u, d, p; 
unsigned long time = 280, beeptime = 50; 
int score = 0, flag = 0; 
#include <EEPROM.h> 
// object initialization 
Adafruit_PCD8544 nokiaLcd(NOKIALCD_PIN_DC, NOKIALCD_PIN_CS, NOKIALCD_PIN_RST); 
Button pushButton(PUSHBUTTON_PIN_1); 
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. 
void setup() 
{ 
 //Serial.begin(9600); 
 pinMode(JOYSTICKPSP_PIN_X, INPUT); 
 pinMode(JOYSTICKPSP_PIN_Y, INPUT); 
 //Initialize Nokia instance 
 nokiaLcd.begin(LCD_SIZE_COL, LCD_SIZE_ROW); 
 nokiaLcd.clearDisplay(); 
 nokiaLcd.setContrast(LCD_CONTRAST); //Adjust display contrast 
 pushButton.init(); 
 slength = 8;               //Start with snake length 8 
 xegg = (nokiaLcd.width()) / 2; 
 yegg = (nokiaLcd.height()) / 2; 
 nokiaLcd.setTextSize(2);          //Initial nokiaLcd 
 nokiaLcd.setTextColor(BLACK); 
 nokiaLcd.setCursor(10, 15); 
 nokiaLcd.setCursor(10, 40); 
 nokiaLcd.display(); 
 delay(4000); 
 nokiaLcd.clearDisplay(); 
 for (i = 0; i <= slength; i++) //Set starting coordinates of snake 
 { 
   x[i] = 25 - 3 * i; 
   y[i] = 10; 
 } 
 for (i = 0; i < slength; i++)  //Draw the snake 
 { 
   nokiaLcd.drawCircle(x[i], y[i], 1, BLACK); 
 } 
 nokiaLcd.display(); 
 dr = true;  //Going to move right initially 
} 
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. 
void loop() 
{ 
 movesnake();    //This is called endlessly 
} 
void movesnake() 
{ 
 int X_val = analogRead(JOYSTICKPSP_PIN_X); 
 int Y_val = analogRead(JOYSTICKPSP_PIN_Y); 
 l = X_val < 400 ? 1 : 0; 
 d = X_val > 650 ? 1 : 0; 
 r = Y_val < 400 ? 1 : 0;; 
 u = Y_val >= 650 ? 1 : 0; 
 p = pushButton.onPress(); 
if (p == HIGH)            //Pause game for 5 seconds 
 { 
   nokiaLcd.clearDisplay(); 
   nokiaLcd.setTextColor(BLACK); 
   nokiaLcd.setCursor(25, 10); 
   nokiaLcd.setTextSize(1); 
   nokiaLcd.print("Pause"); 
   nokiaLcd.display(); 
   delay(1000); 
   while (!pushButton.onPress()); 
   nokiaLcd.clearDisplay(); 
   redraw();          //Redraw the snake and egg at the same position as it was 
 } 
 if (millis() % time == 0) //this condition becomes true after every 'time' milliseconds...millis() returns the time since launch of program 
 { 
 direct(); 
   if (flag == 0)                                //flag 0 means no directional key has been pressed in the last 'time' milliseconds 
   { 
     if (dr == true) { 
       tempx = x[0] + 3;  // so the snake moves one step in the direction it is moving currently 
       tempy = y[0]; 
     } 
     if (dl == true) { 
       tempx = x[0] - 3;  //The new coordinates of head of snake goes in tempx,tempy 
       tempy = y[0]; 
     } 
     if (du == true) { 
       tempy = y[0] - 3; 
       tempx = x[0]; 
     } 
     if (dd == true) { 
       tempy = y[0] + 3; 
       tempx = x[0]; 
     } 
   } 
   flag = 0; 
   checkgame();                              //Check if snake has met egg or coincided with itself 
   checkegg(); 
   if (tempx <= 0) { 
     tempx = 84 + tempx; //If the new coordinates are out of screen, set them accordingly 
   } 
   else if (tempx >= 84) { 
     tempx = tempx - 84; 
   } 
   if (tempy <= 0) { 
     tempy = 48 + tempy; 
   } 
   else if (tempy >= 48) { 
     tempy = tempy - 48; 
   } 
   for (i = 0; i <= slength; i++) //Change the coordinates of all points of snake 
   { 
     xx = x[i]; 
     yy = y[i]; 
     x[i] = tempx; 
     y[i] = tempy; 
     tempx = xx; 
     tempy = yy; 
   } 
   drawsnake();           //Draw the snake and egg at the new coordinates 
 } 
} 
void checkgame()       //Game over checker 
{ 
 for (i = 1; i < slength; i++)        //Checking if the coordinates of head have become equal to one of the non head points of snake 
 { 
   if (x[i] == x[0] && y[i] == y[0]) 
   { 
     bh = EEPROM.read(1); 
     bl = EEPROM.read(0); 
     high = (((0xff00 + bh) << 8) + bl); 
     if (score > high) 
     { 
       high = score; 
       bh = (high >> 8); 
       bl = high & 0xff; 
       EEPROM.write(1, bh); 
       EEPROM.write(0, bl); 
     } 
     nokiaLcd.clearDisplay(); 
     nokiaLcd.setTextColor(BLACK); 
     nokiaLcd.setTextSize(1); 
     nokiaLcd.setCursor(20, 12); 
     nokiaLcd.print("Game Over"); 
     nokiaLcd.setCursor(15, 30); 
     nokiaLcd.print("Score: "); 
     nokiaLcd.print(score); 
     nokiaLcd.setCursor(15, 40); 
     nokiaLcd.print("High: "); 
     nokiaLcd.print(high); 
     nokiaLcd.display(); 
     beep(20, 5000); 
     nokiaLcd.clearDisplay(); 
     slength = 8;            //Resetting the values 
     score = 0; 
     time = 280; 
     redraw();              //Restart game by drawing snake with the resetted length and score 
   } 
 } 
} 
void checkegg()      //Snake meets egg 
{ 
 if (x[0] == xegg or x[0] == (xegg + 1) or x[0] == (xegg + 2) or x[0] == (xegg - 1)) //Snake in close vicinity of egg 
 { 
   if (y[0] == yegg or y[0] == (yegg + 1) or y[0] == (yegg + 2) or y[0] == (yegg - 1)) 
   { 
     score += 1;                     //Increase length,score and increase movement speed by decreasing 'time' 
     slength += 1; 
     if (time >= 90) 
     { 
       time -= 5; 
     } 
     nokiaLcd.fillRect(xegg, yegg, 3, 3, WHITE);  //Delete the consumed egg 
     nokiaLcd.display(); 
     beep(35, beeptime);             //Beep with a sound of 35Hz for 'beeptime' ms 
     xegg = random(1, 80);           //Create New egg randomly 
     yegg = random(1, 40); 
   } 
 } 
} 
void direct()                  //Check if user pressed any keys and change direction if so 
{ 
 if (l == HIGH and dr == false)  //when key LEFT is pressed ,L will become low 
 { 
   dl = true; du = false; dd = false; 
   tempx = x[0] - 3;            //Save the new coordinates of head in tempx,tempy 
   tempy = y[0]; 
   flag = 1;                   //Do not change direction any further for the ongoing 'time' milliseconds 
 } 
 else if (r == HIGH and dl == false) 
 { 
   dr = true; du = false; dd = false; 
   tempx = x[0] + 3; 
   tempy = y[0]; 
   flag = 1; 
 } 
 else if (u == HIGH and dd == false) 
 { 
   du = true; dl = false; dr = false; 
   tempy = y[0] - 3; 
   tempx = x[0]; 
   flag = 1; 
 } 
 else if (d == HIGH and du == false) 
 { 
   dd = true; dl = false; dr = false; 
   tempy = y[0] + 3; 
   tempx = x[0]; 
   flag = 1; 
 } 
 else if (p == HIGH)            //Pause game for 5 seconds 
 { 
   nokiaLcd.clearDisplay(); 
   nokiaLcd.setTextColor(BLACK); 
   nokiaLcd.setCursor(25, 10); 
   nokiaLcd.setTextSize(1); 
   nokiaLcd.print("Pause"); 
   nokiaLcd.display(); 
   delay(1000); 
   while (!pushButton.onPress()); 
   nokiaLcd.clearDisplay(); 
   redraw();          //Redraw the snake and egg at the same position as it was 
 } 
} 
void drawsnake()        //Draw snake and egg at newly changed positions 
{ 
 nokiaLcd.fillRect(xegg, yegg, 3, 3, BLACK);   //Draw egg at new pos 
 nokiaLcd.drawCircle(x[0], y[0], 1, BLACK);    //Draw new head of snake 
 nokiaLcd.drawCircle(x[slength], y[slength], 1, WHITE); //Delete old tail of snake 
 nokiaLcd.display(); 
} 
void redraw()   //Redraw ALL POINTS of snake and egg 
{ 
 nokiaLcd.fillRect(xegg, yegg, 3, 3, BLACK); 
 for (i = 0; i < slength; i++) 
 { 
   nokiaLcd.drawCircle(x[i], y[i], 1, BLACK); 
 } 
 nokiaLcd.display(); 
} 
void beep (int freq, long tb)          //This function creates a sound of frequency 'freq' Hz and for a duration of 'tb' milliseconds 
{ 
 int x; 
 long delayAmount = (long)(500 / freq);     //Calculate time duration of half cycle 
 long loopTime = (long)(tb / (delayAmount * 2)); //Calculate no. of cycles 
 for (x = 0; x < loopTime; x++) // One iteration produces sound for one cycle 
 { 
   digitalWrite(PIEZOSPEAKER_PIN_SIG, HIGH);  //High for half cycle 
   delay(delayAmount); 
   digitalWrite(PIEZOSPEAKER_PIN_SIG, LOW);   //Low for half cycle 
   delay(delayAmount); 
 } 
 delay(2); 
 //a little delay to make all notes sound separate 
}  
 Upload the code to your Arduino, and you should be set. 
Boxing
We thought is would be cool to put our creation inside an Arduino box, so we cut it out nicely, so that the button, switch, joystick and screen are showing, but the board is underneath, and that's basically it!
3.jpg
Snake in an Arduino Box
 

Comments

Similar projects you might like

BluSpike - Community Driven BLE Sensor Network

Project tutorial by Moheeb Zara

  • 26 views
  • 0 comments
  • 2 respects

NeoPixel Thermometer!

Project tutorial by fmattiussi

  • 41 views
  • 1 comment
  • 3 respects

Arduino - Have Fun with Color Sensor

Project tutorial by khanhhs

  • 921 views
  • 0 comments
  • 13 respects

Arduino - Web-Based Thermometer

Project tutorial by khanhhs

  • 988 views
  • 0 comments
  • 15 respects

Using Python and Arduino MKR1000 for Secure IoT

Project tutorial by Luigi Francesco Cerfeda

  • 3,050 views
  • 1 comment
  • 15 respects

Tech-Tris

Project tutorial by Simone Adobs

  • 83 views
  • 0 comments
  • 2 respects
Add projectSign up / Login