// Define a pin we'll place an LED on
int led = D3;
int brightness = 0;
int fadeAmount = 5;
Servo Preggo;
int PreggoSig = D0;
int day = 0;
float period_schedule[] = {0,.2,.4,.6,.8,1.1,1.4,1.7,2.0,2.4,2.6,2.8,3.0,2.6,2.2,2.0,1.8,1.8,1.6,1.6,1.4,1.4,1.2,1.2,1.0,1.0,0.8};
float period_status = period_schedule[0];
float period_status_new =0;
float x = 0;
int y = 0;
int test = 0;
void setup() {
Preggo.attach(PreggoSig);
Particle.subscribe("day_change", myHandler);
Serial.begin(9600);
// Particle.function("servo", servoControl);
// Set up the LED for output
pinMode(led, OUTPUT);
}
void loop() {
if(day > 27){
day = 0;
}
period_status_new = period_schedule[day];
x = period_status_new - period_status;
// x = map(x, -1.5, 1.5, 10, 170);
x = x*50.0+90.0;
Serial.println(period_status);
y = (int) x;
if (period_status_new <= 2.9) {
test = 0;
}
if (x!=0) {
Preggo.write(y);
delay(500);
if (period_status_new >= 2.9) {
if (test == 0){
Preggo.write(90);
delay(200);
Preggo.write(88);
delay(200);
Preggo.write(86);
delay(200);
Preggo.write(84);
delay(200);
Preggo.write(82);
delay(200);
test =1;
}
}
}
period_status = period_status_new;
if (period_status >= 2.9) {
//et the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
// delay(30);
}
else{
brightness = 0;
analogWrite(led,brightness);
}
}
void myHandler(const char *event, const char *data){
day = day +1;
}
// Servo Preggo;
// int PreggoSig = D0;
// int day = 0;
// float period_schedule[] = {0,.2,.4,.6,.8,1.1,1.4,1.7,2.0,2.4,2.6,2.8,3.0,2.6,2.2,2.0,1.9,1.8,1.7,1.6,1.5,1.4,1.3,1.2,1.1,1.0,0.9};
// int period_status = period_schedule[0];
// int period_status_new =0;
// int x = 0;
// // int position = 0;
//
//
// void setup() {
// Preggo.attach(PreggoSig);
// Particle.subscribe("day_change", myHandler);
// Serial.begin(9600);
// // Particle.function("servo", servoControl);
// }
//
// void loop() {
// // if(day > 10){
// // day = 0;
// // }
// // period_status_new = period_schedule[day];
// // x = period_status_new - period_status;
// // x = map(x, -2, 2, 50, 130);
// // Preggo.write(x);
// // delay(1000);
// // period_status = period_status_new;
// Serial.println(period_schedule[3]);
//
// }
//
// void myHandler(const char *event, const char *data){
// // We'll turn the LED on
// // day = day +1;
// // Preggo.write(100);
// // delay(3000);
// // Preggo.write(90);
// // delay(1000);
// }
// // int servoControl(String command)
// // {
// // int newPos = command.toInt();
// // position = constrain(newPos, 0, 180);
// // Preggo.write(position);
// //
// // 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. .