Our final concept is a our coin counter that encourages children to set saving goals by rewarding them with a short light show each time they reach a goal of 1, 3, and 5 dollars. There are four rectangular slots at the top of the box. Each slot counts 1, 5, 10, and 25 cents to coordinate with a penny, nickel, dime and quarter. Once you reach your goal, the lights in the box will light up and the light show will get longer as the amount collected in the box increases. Once you have reached your final goal you can lift up the lid and collect your money. The video, hero shots, and code are posted below.
Video Link: https://vimeo.com/97896975
hero shot |
insert coin |
lighting up |
Code:
#include <Adafruit_NeoPixel.h>
#define PIN 6
int val1;
int val2;
int val3;
int val4;
int setPoint1 = 100;
int setPoint2 = 100;
int setPoint3 = 100;
int setPoint4 = 100;
//int A = 100;
//int B = 300;
boolean countcheck1 = false;
boolean countcheck2 = false;
boolean countcheck3 = false;
boolean countcheck4 = false;
int count = 0;
int changes = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 2, NEO_GRB + NEO_KHZ800);
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(A2, INPUT);
Serial.begin(9600);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
strip.begin();
strip.show();
// stripone.begin();
// stripone.show();
}
void loop() {
val1 = analogRead(A3); // Read the analogue input value
//Serial.print("1ai");
//Serial.println(aiValue1);
//Serial.print("slot1count");
//Serial.println(slot1count);
if (val1 < setPoint1 && countcheck1 == false)
{ count = count + 5;
Serial.println("count1");
countcheck1 = true;
}
if (val1 > setPoint1)
{ countcheck1 = false;
}
val2 = analogRead(A4); // Read the analogue input value
//Serial.print("2ai");
//Serial.println(aiValue2);
//Serial.print("slot2count");
//Serial.println(slot2count);
if (val2 < setPoint2 && countcheck2 == false)
{ count = count + 10;
Serial.println("count2");
countcheck2 = true;
}
if (val2 > setPoint2)
{ countcheck2 = false;
}
val3 = analogRead(A5); // Read the analogue input value
//Serial.print("1ai");
//Serial.println(aiValue1);
//Serial.print("slot1count");
//Serial.println(slot1count);
if (val3 < setPoint3 && countcheck3 == false)
{ count = count + 25;
Serial.println("count3");
countcheck3 = true;
}
if (val3 > setPoint3)
{ countcheck3 = false;
}
val4 = analogRead(A2); // Read the analogue input value
if (val4 < setPoint4 && countcheck4 == false)
{ count = count + 1;
Serial.println("count4");
countcheck4 = true;
}
if (val4 > setPoint4)
{ countcheck4 = false;
}
if (count > 100)
{ strip.begin();
strip.show();
if (changes == 0) {
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(0, 0, 0), 50); // Nothing
strip.show();
changes = 1;
}
}
if (count > 300)
{ strip.begin();
strip.show();
if (changes == 1) {
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(0, 0, 0), 0); // Nothing
strip.show();
changes = 2;
}
}
if (count > 500)
{ strip.begin();
strip.show();
if (changes == 2) {
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(0, 0, 0), 0); // Nothing
strip.show();
changes = 3;
}
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
No comments:
Post a Comment