For this assignment, I created a diffuser using my LEGO Ghostbusters Car. I wrapped the 3 LED’s within a semi-transparent paper packet and placed the wrapped LED’s within the main section of the car which was surrounded LEGO glass pieces.
I set up the commands as weapon modes of the Ghostbuster Car, in case ghosts were to attack. Each attack had a different effect through the LED.
The three weapon modes were:
ProtonGun – Emitted radiating pulses of Red, Green and Blue light
IonCannon – Alternates between Violet and Yellow
NeutronaGun – The interior of the car becomes Orange
Components:
- Arduino Uno
- Breadboard
- 3 LEDs (rgb)
- 3 220Ω Resistors
- jumper wires
- USB cable
- laptop
/* * Ghostbusters * --------------- * Serial commands control the brightness of R,G,B LEDs * * Command structure is "<WeaponMode>", where "WeaponMode" is * one of "ProtonGun","IonCannon",or "NeutronaWand" * E.g. "ProtonGun" Emitted radiating pulses of Red, Green and Blue light * "IonCannon" Alternates between Violet and Yellow * "NeutronaWand" The interior of the car becomes Orange * * Created 11 September 2016 */ String weaponmode; char serInString[200]; // array that will hold the different bytes of the string. 100=100characters; // -> you must state how long the array will be else it won't work properly char weaponcolor; int colorVal; int wait = 5; int j = 0; // Program variables int redVal = 255; // Variables to store the values to send to the pins int greenVal = 1; // Initial values are Red full, Green and Blue off int blueVal = 1; int redPin = 11; // Red LED, connected to digital pin 9 int greenPin = 10; // Green LED, connected to digital pin 10 int bluePin = 9; // Blue LED, connected to digital pin 11 void setup() { pinMode(redPin, OUTPUT); // sets the pins as output pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); Serial.begin(9600); analogWrite(redPin, 0); // set them all to mid brightness analogWrite(greenPin, 127); // set them all to mid brightness analogWrite(bluePin, 0); // set them all to mid brightness Serial.println("Ghosts are coming !! Choose your weapon mode:"); } void loop () { // clear the string memset(serInString, 0, 200); readSerialString(serInString); //read the serial port and create a string out of what you read weaponmode = String(serInString); weaponcolor = serInString[0]; Serial.println(weaponmode); if( weaponcolor == 'p' || weaponcolor == 'i' || weaponcolor == 'n') { if(weaponcolor == 'p') { for(int i=0; i<=5; i++) { analogWrite(redPin, 255); analogWrite(greenPin, 0); analogWrite(bluePin, 0); delay(200); analogWrite(redPin, 0); analogWrite(greenPin, 255); analogWrite(bluePin, 0); delay(200); analogWrite(redPin, 0); analogWrite(greenPin, 0); analogWrite(bluePin, 255); delay(200); } } else if(weaponcolor == 'i') { for(int i =0; i<=10; i++) { analogWrite(redPin, 153); analogWrite(greenPin, 51); analogWrite(bluePin, 255); delay(500); analogWrite(redPin, 255); analogWrite(greenPin, 255); analogWrite(bluePin, 0); delay(500); } } else if(weaponcolor == 'n') { analogWrite(redPin, 255); analogWrite(greenPin, 128); analogWrite(bluePin, 0); } } delay(100); // wait a bit, for serial data } //read a string from the serial and store it in an array //you must supply the array variable void readSerialString (char *strArray) { int i = 0; if(!Serial.available()) { return; } while (Serial.available()) { strArray[i] = Serial.read(); i++; } }