Back to Parent

//combined with 5 IFTTT applets, this code takes google calendar events
//describing a woman's period and translates them into ambient light and motion
//codified into phases of a 3D printed moon

//Reference for servo: http://diotlabs.daraghbyrne.me/6-controlling-outputs/servo/

//establish LED pins and colors

int redPin = D1;    // RED pin of the LED to PWM pin **A0**
int greenPin = D2;  // GREEN pin of the LED to PWM pin **D0**
int bluePin = D3;   // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255</td>
bool ovulation = false; //ovulation variable

int servoPin = A5; //servo pin at A5
int servoPosition = 0;//set initial servo position to 0
int servoTarget = 0;//set target servo position to 0
Servo servo;

void setup()
{

   //Register our Particle to control the servo
   Particle.function( "pos", setPosition );
   Particle.function( "ovo", ovControl );
   servo.attach( servoPin );
   servo.write( servoPosition );

  // Set up our RGB LED pins for output
  pinMode( redPin, OUTPUT);
  pinMode( greenPin, OUTPUT);
  pinMode( bluePin, OUTPUT);

  //for debugging purposes, talk to the thing
  Serial.begin( 9600 );

}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
  ovControl(ovulation); //call the ovulation control function
  //servo ease code from Lab class
  if( servoPosition != servoTarget )
  {
      if( servoPosition > servoTarget ){
          servoPosition--;
      }else{
        servoPosition++;
        }
      servoPosition = constrain( servoPosition, 0, 255 );

      servo.write( servoPosition );
    }
  delay(75);
}
//RGB LED control code from first lab class
void setRGBColor( int r, int g, int b ){
  redValue = r;
  greenValue = g;
  blueValue = b;
  analogWrite(redPin, 255 - redValue);
  analogWrite(greenPin, 255 - greenValue);
  analogWrite(bluePin, 255 - blueValue);
}
//servo control function from lab
int setPosition( String command ){

  Serial.println( "setSpeed: " + command );

  int value = command.toInt();
  if( value < 0 ) return -1;
  if( value > 180 ) return -1;

  servoTarget = constrain( value, 0, 180 );
  return 1;

}
//ovulation control function
bool ovControl(bool ovo){
  if (ovo == true){
    setRGBColor(255,160,0);
  }
  else{
    setRGBColor(255,255,255);
  }
  return 1;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0