What I am trying to do is…
[ The Box have eyes - one is just drawing dot, another one is photo cell censor
If you put the light with flashlight or block (cover) the eye (actually photh cell),
the buzzer start to sound.
It should sounds like irritating or being surprised. ]
And I connect devices that I have
(1.Full sized breadboard
2. Particle Photon with Headers
3.NeoPixel Diffused 5mm Throgh-Hole LED
4.Photo cell(CdS photoresistor
5.Piezo Buzzer)
like this…
And create code like this…
//belongs to Yunki Min
//The Box have eyes - one is just drawing dot, another one is photo cell censor
//If you put the light with flashlight or block (cover) the eye (actually photh cell), the buzzer start to sound.
//It should sounds like irritating or being surprised.
// Declare some variables
int publishLight = A0;
int ledPin = D2;
int speakerPin = D0;
// Create a software timer to publish at an interval
Timer publishBrightness(1000, publish);
void setup() {
// Make the A0 pin an INPUT
pinMode(A0, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
//Publish Brightness reading
publishBrightness.start();
}
void loop() {
// Pin SetUp
publishLight = analogRead(A0);
//update Temp every .2 seconds
delay(200);
//}
//void light() {
int melody[] = { 349, 349, 523, 523, 587, 587, 523, 247,247,220,220,197,196,349}; //C4,G3,G3,A3,G3,0,B3,C4
//note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {8,4,4,4,4,4,4,4,4,4,4,4,4,4 };
if (publishLight > 1000){
digitalWrite(ledPin, HIGH);
delay(5000);
//digitalWrite(ledPin, LOW);
//delay(1000);
}
else {
for (int thisNote = 0; thisNote < 15; thisNote++) {
int noteDuration = 1400/noteDurations[thisNote];
tone(speakerPin, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
//noTone(speakerPin);
}
// The publish function is called every 1.5s
void publish(){
// Publish something
Particle.publish("Yunki", String(publishLight));
// Increment counter
publishLight;
}
other thing is fine… but the photocell input sensor seems not work.
Could you help me to solve this…?