Skip to content

Instantly share code, notes, and snippets.

@gatana
Last active March 31, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatana/f22896c45ec3e1907641a984fcc6c731 to your computer and use it in GitHub Desktop.
Save gatana/f22896c45ec3e1907641a984fcc6c731 to your computer and use it in GitHub Desktop.
//include sortfware to serial port communication
#include <SoftwareSerial.h>
#include <MP3.h>
//mug music. Ana Sofia Remis. March 2016
//thanks to Bonnie Eisenman for the idea
//Michael Wolf for guidance along the way!
//Jess Herzog, Shane Cashman, & Mami for support
//Elechouse for the library at https://github.com/elechouse/Mp3Shield/blob/master/MP3.h
//TNS DT BFA Lab Midterm
//capacitive touch sensor library
#include <CapacitiveSensor.h>
//* Uses a high value resistor e.g. 10M between send pin and receive pin
//* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
//* Receive pin is the sensor pin - try different amounts of foil / metal on this pin
//Use a 1 megohm resistor (or less maybe) for absolute touch to activate.
//With a 10 megohm resistor the sensor will start to respond 4-6 inches away.
//With a 40 megohm resistor the sensor will start to respond 12-24 inches away (dependent on the foil size). Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.
/** define mp3 class */
MP3 mp3;
CapacitiveSensor cs_4_2 = CapacitiveSensor(4, 2);
// 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire/foil if desired
int tempsensorPin = 0;
int reading;
int currentSong;
//declare functions
//temp sensor [when temp sensor values go higher than _, play tune4.
//when farenheight temp sensor values [tempOutput] are lower than _ play tune5
//when [tempOutput] is between 70-73, play [trigger] tune 6
int tempF(int temperatureF) {
}
void setup() {
Serial.begin(9600); //9600 baud serial communication
//intialize library
mp3.begin(MP3_SOFTWARE_SERIAL);
//stop
mp3.stop();
// callibrate sensor
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
//not sure if I need the below
pinMode(tempsensorPin, OUTPUT); // tempin
}
void loop() {
long total1 = cs_4_2.capacitiveSensor(30);
//temp sensor
//getting the voltage reading from the temperature sensor
reading = analogRead(tempsensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
//function check sensors
Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000);
//delay(12000);
if (temperatureF > 80) {
mp3.play_sd(0x0005);
delay (1200);
} else if (total1 > 30) {
mp3.play_sd(0x0007);
delay (6000);
} else if (total1 < 0) {
mp3.play_sd(0x0006);
delay (7000);
}
else if (temperatureF < 69) {
mp3.play_sd(0x0008);
delay(17000);
}
//once a song starts playing you dont wanna play another one yet
//(use delays the length of the song) OR debouncing
//Serial.print("debug");
//touch sensor
//declare touch variable types
// print sensor output 1
Serial.print("\t");
Serial.println(total1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment