This is a music box that plays "Mary Had a Little Lamb", creates a precautionary noise, and has a light
that can dim. There is an open front component that houses the precision servo and a back component
that houses all the electrical parts and wires. Within the back component, there is a Circuit Playground
Express(CPE) and a breadboard that controls and commands the entire box. Connected to the CPE is
the breadboard which houses a 1k resistor that connects to a white LED with a blue potentiometer that
is off to the side. The LED can be seen through a square hole on the top of the back component of the
box. When the potentiometer is turned left and right, it causes the white LED to dim and brighten. A
flathead screwdriver goes through the top of the back of the box and connects to the potentiometer for
the user to move more easily. A servo motor sits in the front open compartment, has a small piece of
wood screwed to its top and is also connected through the breadboard, and is controlled by the CPE.
A button is connected to said servo and when pressed, the servo and its wood piece spin back and
forth 180 degrees to create a precautionary noise. A small plastic rod also goes through the top of the
back component of the box for the user to push more easily. Finally, a speaker on the CPE can play a
short melody with the flip of a switch that is also found on the CPE. Another plastic rod goes through
the top of the back component of the box for the user to move the switch more easily. How could one
decorate this box to look more appealing?
/****************************
Music Light Percussion Box
****************************/
#include <Servo.h>
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>
#define led 10
Servo myservo; //create servo object to control a servo
//Variables
int neoState = 0;
int bCurrent = 0;
int bPrevious = 0;
int pot = 0;
void setup()
{
CircuitPlayground.begin(); //starts up playground
myservo.attach(A6); // attaches the servo from A6 on the CPE to pin 9 on the breadboard
pinMode (led, OUTPUT); //LED output
Serial.begin(9600);
delay(1000);
}
void loop()
{
if (digitalRead(CPLAY_RIGHTBUTTON)) //makes servo turn 180 degrees back and fourth
{
delay(200);
myservo.write(180);
delay(200);
delay(200);
myservo.write(0);
delay(200);
}
if (digitalRead(CPLAY_SLIDESWITCHPIN)) //if switch on, melody plays
"Marry Had a Little Lamb"
{
CircuitPlayground.playTone(800, 200);
CircuitPlayground.playTone(700, 200);
CircuitPlayground.playTone(600, 200);
CircuitPlayground.playTone(700, 200);
CircuitPlayground.playTone(800, 200);
CircuitPlayground.playTone(800, 200);
CircuitPlayground.playTone(800, 200);
delay(400);
CircuitPlayground.playTone(700, 200);
CircuitPlayground.playTone(700, 200);
CircuitPlayground.playTone(700, 200);
delay(400);
CircuitPlayground.playTone(800, 200);
CircuitPlayground.playTone(1000, 200);
CircuitPlayground.playTone(1000, 200);
}
//Potentiometer control
pot = analogRead (A4);
Serial.println (pot);
pot = map(pot, 1, 1024, 1, 255);
analogWrite(led, pot);
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.