Remove these ads by
Signing UpStep 1: Red Eyes
The bag is the one given to each employee to decorate. I used an Android robot toy from Google. The head comes off. I drilled out the eyes and inserted tri-color LEDs from Radio Shack (http://www.radioshack.com/product/index.jsp?productId=3020765).
There is a ribbon cable with going through a hole in the bag and a hole in the lid to connect to the prototype board connected to the Arduino (see next step). The cable as made using a ribbon cable (https://www.adafruit.com/products/793), and then the LEDs soldered in after stripping one end of the ribbon cables and attaching bare female connectors (http://www.pololu.com/catalog/product/1930), with some shrink tubing used to keep the wires from shorting.
Code is below:
/*************************************************************
Motor shield
http://www.instructables.com/id/Arduino-Motor-Shield-Tutorial/
Function pins per Ch. A pins per Ch. B
Direction D12 D13
PWM D3 D11
Brake D9 D8
Current Sensing A0 A1
lcd code from http://www.arduino.cc/playground/Learning/SparkFunSerLCD
LCD is 20x4
for Leonardo need to use Serial1 class
*************************************************************/
const int IRthreshold = 180;
const int IRPin = 3; // Read IR value on analog 3
const int SignalPin = A2; // send signal to sound Arduino
const int RedPin = A4;
const int BluePin = A5;
boolean cardsensed = false;
boolean LEDflag = false;
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long timestamp = 0; // used to keep track of how long IR sensor blocked
const long MotorDelay = 500; // keep motor going for half a second after IR sensor clears
const long LEDdelay = 4000;
int val = 0;
int count = 0;
void setup()
{
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
pinMode(SignalPin, OUTPUT);
digitalWrite(SignalPin, LOW);
pinMode(RedPin, OUTPUT);
pinMode(BluePin, OUTPUT);
Serial1.begin(9600);
delay(1000); // time to settle in, just in case
clearLCD();
backlightOn();
selectLineOne();
delay(10);
Serial1.print("Happy Valentines Day");
delay(10);
selectLineTwo();
Serial1.print(" CCE!");
delay(10);
selectLineThree();
Serial1.print("I now have:");
delay(10);
blueLED(); // blue at baseline
}
void loop()
{
val = analogRead(IRPin);
if (val > IRthreshold) // path blocked
{
cardsensed = true;
LEDflag = true;
timestamp = millis();
//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
redLED(); // red when it's gotten a card
}
if(val < IRthreshold)
{
if(cardsensed)
{
if ((millis()-timestamp) >= MotorDelay)
{
cardsensed = false;
analogWrite(3,0); // turn off motor, but let it coast so no brake
count++;
selectLineFour();
Serial1.print(count);
Serial1.print(" Valentines");
digitalWrite(SignalPin, HIGH);
delay(20);
digitalWrite(SignalPin, LOW);
}
}
if(LEDflag)
{
if ((millis()-timestamp) >= LEDdelay)
{
LEDflag = false;
blueLED(); // back to being sad and blue
}
}
}
}
///////////////////////////// FUNCTIONS ////////////////////////////////
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial1.write(0xFE); //command flag
Serial1.write(128); //position
}
void selectLineTwo(){ //puts the cursor at line 2 char 0.
Serial1.write(0xFE); //command flag
Serial1.write(192); //position
}
void selectLineThree(){ //puts the cursor at line 3 char 0.
Serial1.write(0xFE); //command flag
Serial1.write(148); //position
}
void selectLineFour(){ //puts the cursor at line 4 char 0.
Serial1.write(0xFE); //command flag
Serial1.write(212); //position
}
void goTo(int position) { //position = line 1: 0-19, line 2: 20-39, etc, 79+ defaults back to 0
if (position<20){ Serial1.write(0xFE); //command flag
Serial1.write((position+128)); //position
}else if (position<40){Serial1.write(0xFE); //command flag
Serial1.write((position+128+64-20)); //position
}else if (position<60){Serial1.write(0xFE); //command flag
Serial1.write((position+128+20-40)); //position
}else if (position<80){Serial1.write(0xFE); //command flag
Serial1.write((position+128+84-60)); //position
} else { goTo(0); }
}
void clearLCD(){
Serial1.write(0xFE); //command flag
Serial1.write(0x01); //clear command.
}
void backlightOn(){ //turns on the backlight
Serial1.write(0x7C); //command flag for backlight stuff
Serial1.write(157); //light level.
}
void backlightOff(){ //turns off the backlight
Serial1.write(0x7C); //command flag for backlight stuff
Serial1.write(128); //light level for off.
}
void backlight50(){ //sets the backlight at 50% brightness
Serial1.write(0x7C); //command flag for backlight stuff
Serial1.write(143); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
Serial1.write(0xFE);
}
void blueLED(){
digitalWrite(BluePin, LOW); // reverse of usual since common
digitalWrite(RedPin, HIGH); // anode
}
void redLED(){
digitalWrite(BluePin, HIGH);
digitalWrite(RedPin, LOW);
}























Not Nice
















Visit Our Store »
Go Pro Today »



