Is it true that Arduinos were designed to fit inside Altoids cans? I may have just remembered that, or I may have just made it up, but how perfectly they fit! To celebrate how well they fit I’ve designed a party box: when the Altoids can is opened, the party ensues; when it is closed, the party ceases.
Materials:
Altoids can
Arduino Uno
3 LED lights
1 320 Ohm resistor
1 10k Ohm resistor
Wires
Tape
Piezo buzzer
Code:
/* Theremin
* ——–
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;
int val = 0;
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 11; // Blue LED, connected to digital pin 11
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
int ramdred = 0;
int ramdblu = 0;
int ramdgrn = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
Serial.begin(9600);
Serial.println(“ready”);
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little
ramdred = random(0, 250);
ramdblu = random(0, 250);
ramdgrn = random(0, 250);
if (val > 0){
for( int i=0; i<50; i++ ) { // play it for 50 cycles
analogWrite(redPin, ramdred);
analogWrite(grnPin, ramdblu);
analogWrite(bluPin, ramdgrn);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
};
}
else {
analogWrite(redPin, 0);
analogWrite(grnPin, 0);
analogWrite(bluPin, 0);
delay(10);
};
Serial.print(val);
Serial.println();
};
Video:
https://youtu.be/ZeF2XRpKqaw