#include "application.h"
// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int flexPin1 = A0;
// Create a variable to hold the FSR1 reading
int flexReading1 = 0;
int flexPin2 = A1;
// Create a variable to hold the FSR2 reading
int flexReading2 = 0;
int photoPin = A2;
int photoCellReading = 0;
// Create a variable to hold the pcr reading
int toneC = 0;
int toneD = 0;
// Define a pin we'll place an LED on
int ledPin = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
int Duration = 0;
int speakerPin = D3;
int notes[] =
{0,
/* C, C#, D, D#, E, F, F#, G, G#, A, A#, B */
3817,3597,3401,3205,3030,2857,2703,2551,2404,2273,2146,2024, // 3 (1-12)
1908,1805,1701,1608,1515,1433,1351,1276,1205,1136,1073,1012, // 4 (13-24)
956, 903, 852, 804, 759, 716, 676, 638, 602, 568, 536, 506, // 5 (25-37)
478, 451, 426, 402, 379, 358, 338, 319, 301, 284, 268, 253, // 6 (38-50)
239, 226, 213, 201, 190, 179, 169, 159, 151, 142, 134, 127 }; // 7 (51-62)
#define NOTE_C2 1908
#define NOTE_C3 956
#define NOTE_D2 1701
#define NOTE_D3 852
void setup()
{
// Set up the LED for output
pinMode(ledPin, OUTPUT);
// Create a cloud variable of type integer
// called 'light' mapped to photoCellReading
pinMode(speakerPin, OUTPUT);
Particle.variable("force1", flexReading1);
Particle.variable("force2", flexReading2);
Particle.variable("light", photoCellReading);
}
void loop()
{
// Use analogRead to read from the sensor
// This gives us a value from 0 to 4095
flexReading1 = analogRead(flexPin1);
flexReading2 = analogRead(flexPin2);
photoCellReading = analogRead(photoPin);
force1makesSound();
force2makesSound();
// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(flexReading1, 0, 4095, 0, 255);
;
// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);
}
void photochangeTone()
{
if(photoCellReading < 530) {
toneC = NOTE_C2;
toneD = NOTE_D2;
}
else{
toneC = NOTE_C3;
toneD = NOTE_D3;
}
delay(0);
}
void force1makesSound()
{
if (flexReading1 < 500 ){
photochangeTone();
tone(speakerPin, toneC, 100);
}
delay(10);
}
void force2makesSound()
{
if (flexReading2 < 500 ){
photochangeTone();
tone(speakerPin, toneD, 100);
}
delay(10);
}
Click to Expand