int redPin = A0;
int greenPin = D0;
int bluePin = D1;
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int redPin1 = A6; // RED pin of the LED to PWM pin **A0**
int greenPin1 = A1; // GREEN pin of the LED to PWM pin **D0**
int bluePin1 = A4;
int redValue1 = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue1 = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue1= 255;
int pos = 0;
Servo myservo;
void setup()
{
// Set up our pins for output
pinMode( redPin, OUTPUT);
pinMode( greenPin, OUTPUT);
pinMode( bluePin, OUTPUT);
analogWrite( redPin, 155);
analogWrite( greenPin, 155);
analogWrite( bluePin, 155);
pinMode( redPin1, OUTPUT);
pinMode( greenPin1, OUTPUT);
pinMode( bluePin1, OUTPUT);
analogWrite( redPin1, 255);
analogWrite( greenPin1,255);
analogWrite( bluePin1, 255);
Spark.subscribe( "CragTweetHY/Event" , handleDoorbellPush2 );
}
void run3()
{
myservo.attach(A7);
analogWrite( redPin, 255);
analogWrite( greenPin, 0);
analogWrite( bluePin, 0);
for(pos = 180; pos > =120; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(60); // waits 15ms for the servo to reach the position
}
delay(10000);
for(pos = 120; pos<=180; pos+=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(60); // waits 15ms for the servo to reach the position
}
myservo.detach();
}
void run4()
{
myservo.attach(A5);
analogWrite( redPin1, 0);
analogWrite( greenPin1, 0);
analogWrite( bluePin1, 255);
for(pos = 180; pos > =120; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(60); // waits 15ms for the servo to reach the position
}
delay(10000);
for(pos = 120; pos<=180; pos+=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(60); // waits 15ms for the servo to reach the position
}
myservo.detach();
}
void handleDoorbellPush2(const char *event, const char *data)
{
if(strcmp(data ,"ZhangMore") == 0)
run3();
if(strcmp(data ,"ShianHeyu") == 0)
run4();
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .