Embedded System Skee-ball
4180 Final Project
Team Members: Sanjida Islam, Micheal Walelign, Adam Tesfai
Overview
The idea is to make an embedded system skee-ball machine where the player can play just by connecting his phone to the machine using Bluetooth. The Bluetooth connection allows the player have direction control to fire the ball. The game has different game modes for different duration time which allows the player to score as much as they can within duration. Once the game ends, the player has the option to get the score on his phone through Bluetooth or via a text message.
Components
- Adafruit Bluefruit LE UART Friend
- Calss D Amplifier
- Speaker
- MOSFET
- 12V Solenoid
- SD card file system
- uLCD
- LED strip
- RGB LED
- RC Servo
- Photo resistors
Wiring
Pin Connections
Bluefruit LE UART
Class D Amplifier
mbed | TPA2005D1 | Speaker |
---|---|---|
gnd | pwr - (gnd), in - | |
Vout(3.3V) or 5V | pwr + | |
p18 | in + | |
out + | + | |
out - | - |
MOSFET and Solenoid
mbed | MOSFET PCB | 12V 1A external device |
---|---|---|
gnd | JP2-2gbd | |
12V | JP2-1 RAW | |
p23 | JP2-3 Control | |
JP1-1 | - | |
JP1-2 | + |
SD Card
mbed | SD card |
---|---|
8 | CS |
5 | DI |
Vout | VCC |
7 | SCK |
GND | GND |
6 | DO |
CD |
uLCD
mbed | uLCD header | =uLCD cable |
---|---|---|
VU=5V | 5V | 5V |
GND | GND | GND |
TX=P13 | RX | TX |
RX=P14 | TX | RX |
P11 | Reset | Reset |
RC Servo
Photo Resistors
RGB LED
RGB LED Strip
C++ Code
main.cpp
#include "mbed.h" #include "Servo.h" //#include "DebounceIn.h" #include "SDFileSystem.h" #include "wave_player.h" #include "uLCD_4DGL.h" #include "Speaker.h" //Speaker mySpeaker(p24); uLCD_4DGL uLCD(p13,p14,p11); // serial tx, serial rx, reset pin; SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card AnalogOut DACout(p18); DigitalOut myled2(LED3); wave_player waver(&DACout); Servo myservo(p21); Serial pc(p28, p27); Serial pc2(USBTX, USBRX); // tx, rx bool keepscore=true;; PwmOut Ctrl(p23); DigitalOut myled(LED1); //DebounceIn hit(p8); AnalogIn photocell(p16); AnalogIn photocell_2(p17); AnalogIn photocell_3(p20); double hole1 = photocell*10; double hole2= photocell_2*10; double hole3 = photocell_3*10; Timer currentTime; int gameTime; //bool gameSel; char bnum=0; char bhit= 0; int score=0; void playEndSound(){ FILE *wave_file; wave_file=fopen("/sd/AirHorn.wav","r"); waver.play(wave_file); fclose(wave_file); } void playStartSound(){ FILE *wave_file; wave_file=fopen("/sd/startGame_new.wav","r"); waver.play(wave_file); fclose(wave_file); } void gameModeSelect() { while(1) { if (pc.getc()=='!') { if (pc.getc()=='B') { //button data bnum = pc.getc(); //button number bhit = pc.getc(); //1=hit, 0=release if(bnum=='2'){ if (bhit=='1') { pc.printf("2 pressed in gamemode\n"); gameTime = 60; myled=1; uLCD.cls(); //playStartSound(); currentTime.start(); break; } else {} //add release code here } if(bnum=='3'){ if (bhit=='1') { pc.printf("2 pressed in gamemode\n"); gameTime = 120; //playStartSound(); currentTime.start(); myled=1; break; } else { } //add release code here } if(bnum=='4'){ if (bhit=='1') { pc.printf("2 pressed in gamemode\n"); gameTime = 180; playStartSound(); currentTime.start(); myled=1; break; } else { } //add release code here } } } } } void gameOver(){ uLCD.text_width(2); //4X size text uLCD.text_height(2); uLCD.printf("\nWelcome\n"); //Default Green on black text wait(2); uLCD.printf("\nSelect \nGame Mode"); wait(2); uLCD.cls(); uLCD.text_width(2.2); //4X size text uLCD.text_height(2.2); uLCD.printf("2 for 60 sec\n"); uLCD.printf("3 for 15 sec\n"); uLCD.printf("4 for 20 sec\n"); wait(3); gameModeSelect(); //uLCD.cls(); //playEndSound(); } int main() { //hit.mode(PullDown); //playStartSound(); myservo=0.; wait(1); //myled=1; //wait(1); //SongPlayer mySpeaker(p26); //mySpeaker.PlayNote(200.0,0.25,0.1); //mySpeaker.PlaySong(note,duration); uLCD.text_width(2); //4X size text uLCD.text_height(2); uLCD.printf("\nWelcome\n"); //Default Green on black text wait(2); uLCD.printf("\nSelect \nGame Mode"); wait(2); uLCD.cls(); uLCD.text_width(2.2); //4X size text uLCD.text_height(2.2); uLCD.printf("2 for 60 sec\n"); uLCD.printf("3 for 2 minutes\n"); uLCD.printf("4 for 3 minutes \n"); wait(3); //uLCD.cls(); gameModeSelect(); while(currentTime.read()<(gameTime)) { //myled2=1; //wait(1); //myled2=0; if (pc.getc()=='!') { if (pc.getc()=='B') { //button data bnum = pc.getc(); //button number bhit = pc.getc(); //1=hit, 0=release switch (bnum) { case '7': //number button 1 if (bhit=='1') { myservo=myservo-0.2; } else { //add release code here } break; case '8': //number button 2 if (bhit=='1') { myservo =myservo+0.2; } else { //add release code here } break; case '1': //number button 2 if (bhit=='1') { keepscore=true; Ctrl.period(0.5); Ctrl=0.2f; //myled = 1; wait(1); Ctrl=0; // pc.printf("1 pressed to fire\n"); }else { //add release code here } break; } } } if(keepscore){ if(hole1<5){ //pc.printf("Values: %d\n", hole1); //pc.printf("covered\n"); score+=10; keepscore=false; } else if(hole2<5){ //pc.printf("Values: %d\n", hole1); //pc.printf("covered\n"); score+=20; keepscore=false; } else if(hole3<5){ //pc.printf("Values: %d\n", hole1); //pc.printf("covered\n"); score+=20; keepscore=false; } } //pc2.printf("test"); pc2.printf("%d\n", score); pc.printf("Score:%i\n",score); wait(.125); uLCD.text_width(3); //4X size text uLCD.text_height(3); uLCD.color(RED); uLCD.printf("Score: %i\n",score); //wait(0.25); uLCD.cls(); //gameOver(); // } gameOver(); }
C# code to send the score to phone
main.cpp
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Twilio; using Twilio.Rest.Api.V2010.Account; using System.IO.Ports; namespace smsmbed { public partial class Form1 : Form { string score; string dataIn; public Form1() { InitializeComponent(); } /*private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { serialPort1.Open(); // serialPort1 = (SerialPort)sender; dataIn = serialPort1.ReadExisting(); //Console.WriteLine("Data rec"); //fake = "100"; this.Invoke(new EventHandler(ShowData)); serialPort1.Close(); } private void ShowData(object sender, EventArgs e) { textBox1.Text = dataIn; } */ private void button2_Click(object sender, EventArgs e) { serialPort1.Open(); // serialPort1 = (SerialPort)sender; dataIn = serialPort1.ReadExisting(); textBox2.Text = dataIn; //Console.WriteLine("Data rec"); //fake = "100"; } private void button1_Click(object sender, EventArgs e) { string playername = textBox1.Text; score = playername + " " + "you" + " " + "scored" + " " + dataIn ; } private void button3_Click(object sender, EventArgs e) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "insertaccountsidhere"; const string authToken = "insertaccounttokenhere"; TwilioClient.Init(accountSid, authToken); var message = MessageResource.Create( body: score, from: new Twilio.Types.PhoneNumber("insertwiliophone#"), to: new Twilio.Types.PhoneNumber("insertpersonalphone#") ); Console.WriteLine(message.Sid); serialPort1.Close(); } } }
The player can write their name and fetch the score to be sent to the phone.
RGB LED strip
main.cpp
#include "mbed.h" #include "PololuLedStrip.h" PololuLedStrip ledStrip(D8); #define LED_COUNT 15 rgb_color colors[LED_COUNT]; Timer timer; // Converts a color from the HSV representation to RGB. rgb_color hsvToRgb(float h, float s, float v) { int i = floor(h * 6); float f = h * 6 - i; float p = v * (1 - s); float q = v * (1 - f * s); float t = v * (1 - (1 - f) * s); float r = 0, g = 0, b = 0; switch(i % 6){ case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } return (rgb_color){r * 255, g * 255, b * 255}; } int main() { timer.start(); while(1) { // Update the colors array. uint32_t time = timer.read_ms(); for(int i = 0; i < LED_COUNT; i++) { uint8_t phase = (time >> 4) - (i << 2); colors[i] = hsvToRgb(phase / 256.0, 1.0, 1.0); } // Send the colors to the LED strip. ledStrip.write(colors, LED_COUNT); } }
Reference: https://os.mbed.com/users/DavidEGrayson/code/PololuLedStrip/file/c3193bc73cff/PololuLedStrip.cpp/
Demo
Please log in to post comments.