Changes

Jump to: navigation, search

Students/Julian Santos III

5,099 bytes added, 03:51, 19 March 2010
Final Project
==Final Project==
===Arduino Scratch Game Controller===
Centipede As someone who has a deep affinity with classic videogames, I have always wanted to create and understand the media more. From analog joysticks to the newly developed accelerometer controllers, I am intrigued by the ways a digital object onscreen could be controlled by a physical analog device in the real world. To further this interest, I wanted to recreate a classic videogame in Scratch for use with as well as recreate a gamepad controller using an Arduino controller http://scratch.mitMicrocontroller.edu/projects/Janussaint/937832
After further research on how this could be best accomplished, I stumbled upon Scratch [http://scratch.mit.edu/] a unique programming platform that makes it easy to create rough sketches of interactive digital media due to its real time condition testing and straight forward approach to program design. After some time being familiar with Scratch, I decided that I was going to recreate a classic videogame while using what I have learned from Arduino programming to make it function as a gamepad.  To help with this transition, I found a simplified controller board specifically made for use with Scratch called a Picoboard [http://www.picocricket.com/picoboard.html] which has sensors and functions much like an Arduino. In order to use the Arduino with Scratch I reappropriated code from a Scratch-board simulation site [http://www.yengawa.com/scratch_arduino] which allows the Arduino to be used in the same way as a Picoboard. On the Arduino, I substituted a potentiometer and a push-button switch to respectively replace the functions on the Picoboard. To complete the controller I wired and soldered all the parts into a plastic housing. I chose to remake the classic topdown shooting videogame Centipede to accommodate the controller. The game is also perfect for using the potentiometer as its dial doesnt rotate a full 360 degrees and the player's controlled vessel in Centipede only moves left and right in a limited enclosed play area (as opposed to a game where the player's controlled vessel has a free full range of motion where at least a four-point setup is needed). I found a Scratch project example of Centipede and reconfigured the language to be used by the Arduino Controller. A roadbump that I found from translating the Arduino's controller to the Scratch game was that the potentiometer read as 0-100, but this was solved creating variables that would set its orientation based on the sensor value. The final result can be found in this link (but can only be playable using the Arduino Controller).Code http://wwwscratch.yengawamit.comedu/projects/Janussaint/937832 ===Video and Images===  ===Function Diagram===  ===Arduino Code===<source lang="html4strict">/* ScratchBoard compatible program */ // digital input pin#define BUTTON 2 //normally open push button switch // analog input pin#define SLIDER 0 //connected to a 100k pontentiometer#define LIGHT 1 // for using light sensors#define SOUND 2 //sitesfor a mic#define R_A 3 #define R_B 4#define R_C 5#define R_D 5 /default/files3-5 analog inputs #define FIRMWAEW_ID 4 /uploads/ScratchBoard1.pde1 Firmware ID #define LED_PIN 13 // response lamp (digital pin 13 is on board LED) const byte req_scratchboard = 1; // request messge from Scratchconst byte mask_scratcharduino = 240; // request mask of Scratch+Ardunioconst byte ch_r_D = 0;const byte ch_r_C = 1;const byte ch_r_B = 2;const byte ch_button = 3;const byte ch_r_A = 4;const byte ch_light = 5;const byte ch_sound = 6;const byte ch_slider = 7;const byte ch_firmware = 15; int sensorValue = 0; // sensor value to send byte inByte = 0; // incoming serial byte void setup(){ // start serial port at 9600 bps: Serial.begin(38400); pinMode(BUTTON, INPUT); // digital sensor is on digital pin 2  // initialize the digital pin as an output: pinMode(LED_PIN, OUTPUT); //digitalWrite(LED_PIN, HIGH); // set the LED on } void loop(){ // if we get a valid byte, read analog ins: if (Serial.available() > 0) { // get incoming byte: inByte = Serial.read(); if (inByte == req_scratchboard) { digitalWrite(LED_PIN, HIGH); // set the LED on  sendValue(ch_firmware, FIRMWAEW_ID); delay(10);  // analog read range from 0 to 1023 // delay 10ms to let the ADC recover:  sensorValue = analogRead(R_D); sendValue(ch_r_D, sensorValue); delay(10);  sensorValue = analogRead(R_C); sendValue(ch_r_C, sensorValue); delay(10);  sensorValue = analogRead(R_B); sendValue(ch_r_B, sensorValue); delay(10);  // read switch, map it to 0 or 1023L sensorValue = map(digitalRead(BUTTON), 0, 1, 0, 1023); sendValue(ch_button, sensorValue);  sensorValue = analogRead(R_A); sendValue(ch_r_A, sensorValue); delay(10);  sensorValue = analogRead(LIGHT); sendValue(ch_light, sensorValue); delay(10);  sensorValue = analogRead(SOUND); sendValue(ch_sound, sensorValue); delay(10);  sensorValue = analogRead(SLIDER); sendValue(ch_slider, sensorValue); delay(10);  digitalWrite(LED_PIN, LOW); // set the LED off } }} void sendValue(byte channel, int value) { byte high = 0; // high byte to send byte low = 0; // low byte to send high = (1 << 7) | (channel << 3) | (value >> 7); low = (0xff >> 1) & value; Serial.write(high); Serial.write(low);}</source>
56
edits

Navigation menu