//
//∆∆∆∆ SERVO STUFF ∆∆∆∆
//
int servoPin = D0;
Servo myServo;
int servoPos = 0;
//Servo theServo;
//int servo1Pos = 0;
//int servo2Pos = 0;
//
//∆∆∆∆ led STUFF ∆∆∆∆
//
int bluePin = D3; // RED pin of the LED to PWM pin **A4**
int greenPin = D1; // GREEN pin of the LED to PWM pin **D0**
//int bluePin = D2; // BLUE pin of the LED to PWM pin **D1**
int red = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int green = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255</td>
//
//∆∆∆∆ PHOTORESISTOR STUFF ∆∆∆∆
//
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;
// Create a variable to hold the light reading
int photoCellReading = 0;
void setup() {
Serial.begin(9600);
//Serial.begin( 9600 );
//Serial.print( "Looped " );
// attaches the servo on the A7 pin to the servo object
myServo.attach( D0 );
//Register our Particle to control the servo
Particle.function("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable("servoPos" , &servoPos , INT );
//
// Set up our pins for output
//pinMode( redPin, OUTPUT);
pinMode( greenPin, OUTPUT);
pinMode( bluePin, OUTPUT);
/*
// turn them all off...
analogWrite( redPin, 0);
analogWrite( greenPin, 0);
*/
//analogWrite( bluePin, blue);
}
void loop() {
// First... On
//digitalWrite(bluePin, HIGH); // Turn ON the LED pins
//delay(1000); // Wait for 1000mS = 1 second
// Now... Off
//digitalWrite(bluePin, LOW); // Turn OFF the LED pins
//delay(1000);
}
int servoControl(String command)
{
/*
int upPos = 100;
int downPos = 10;
// Convert
if(command.equals("up"))
{
int newPos = upPos();
Serial.println("going up");
}
else if(command.equals("down"))
{
int newPos = downPos; //test these
Serial.println("going down");
}
else
{
Serial.println("incorrect servo command, taking no action");
return 1;
}
Serial.println(newPos);
//int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 0 , 180);
//servo2Pos = constrain( newPos, 0 , 180);
// Set the servo
myServo.write( servoPos );
//theServo.write( servo2Pos );
//
//WE SHOULD TIME HOW LONG IT TAKES TO TRAVEL, THEN JUST BLINK FOR THAT LONG
//
//blinkLED(100, 100, 120);
//setLED(0,250,0);
// done
*/
// Convert
int upPos = 100;
int newPos = 90;
if(command.equals("up"))
{
newPos = upPos;
Serial.println("going up");
//Serial.print(newPos );
}
else if(command.equals("down"))
{
newPos = 10; //test these
Serial.println("going down");
}
else{
newPos = command.toInt();
}
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 0 , 180);
// Set the servo
myServo.write( servoPos );
//Serial.println("wazzup" );
Serial.print(newPos );
//BLINK IT
blinkLED(100, 100, 120);
delay(3000);
//blinkLED(230, 230);
return 1;
}
//function for controlling individual LEDs
int blinkLEDIndividualLEDs(int g, int b)
{
//red = r;
green = g;
blue = b;
// write the mixed color
int delayTime = 1000;
int totalTime = 10000;
int numberBlinks = totalTime/delayTime;
int blank = 0;
for(int i = 0; i < numberBlinks; i++){
//analogWrite( redPin, red);
analogWrite( greenPin, green);
analogWrite( bluePin, blue);
delay(delayTime);
//analogWrite( redPin, blank);
analogWrite( greenPin, blank);
analogWrite( bluePin, blank);
delay(delayTime);
}
return 1;
}
//function for controlling RGB LED
int blinkLED(int r, int g, int b)
{
red = r;
green = g;
blue = b;
// write the mixed color
int delayTime = 1000;
int totalTime = 10000;
int numberBlinks = totalTime/delayTime;
int blank = 0;
for(int i = 0; i < numberBlinks; i++){
analogWrite( redPin, red);
analogWrite( greenPin, green);
analogWrite( bluePin, blue);
delay(delayTime);
analogWrite( redPin, blank);
analogWrite( greenPin, blank);
analogWrite( bluePin, blank);
delay(delayTime);
}
return 1;
}
int setLED(int r, int g, int b)
{
red = r;
green = g;
blue = b;
analogWrite( redPin, red);
analogWrite( greenPin, green);
analogWrite( bluePin, blue);
return 1;
}
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. .