Skill Dev IV - Working with Outputs - Motors and Movement

Made by Stephanie Ho ·

* get to know the actuators you can use to create compelling outputs and interactivity * learn how to program the behavior of movement using servos, fans or solenoids to create interactivity and communicate information * explore cloud functions as a way to quickly prototype and simulate online data. * explore actuators and the kinds of opportunities they might create for your second project. * to structure changes and transitions in code

Created: December 4th, 2023

0

I wanted to create a 'countdown' clock that was represented both with the sweeping motor and colored lights indicating the time passage. I realized a number of things through this exercise:

1) The motor would not sweep a full 360. I tested different codes trying *not* to have it reverse but rather continue to sweep. From this I learned that it's important to understand the limits of the devices being used.

2) I had issues with the lighting - the brightness of the lights, when 'LOW', still appeared to be on as the timer counted down. This will be adjusted by setting the brightness. 

3) I also realized an alternative to this code would be turning on and and off a light based on the position of the motor. This however would be more difficult to calculate, although potentially more applicable on a larger scale clock or visual of a countdown.

4) I wanted to be able to start and stop the timer through a Particle command. I added this as a Particle function.

0
int servoPin = A3;
int servoPosition = 0;
int ledRed = D2;
int ledYellow = D3;
int ledGreen = D4; 
int timer = 1000*60*1; //1 minute timer
bool timerStarted = false;

Servo servo;


void setup() {
    servo.attach(servoPin);
    pinMode(ledRed, OUTPUT);
    pinMode(ledYellow, OUTPUT);
    pinMode(ledGreen, OUTPUT);
    servo.write(0); //set to 0 degrees
    digitalWrite(ledRed,HIGH);
    Particle.function("StartTimer",controlTimer);

}

int controlTimer(String command){
    if(command=="start"){
        timerStarted=true;
        return 1;
    }
    else if (command=="stop"){ //stops after the loop is finished
        timerStarted=false;
        return -1;
    }
    else{
        return-1;
    }
}
    
void loop(){
if(timerStarted){
    for(int i=0; i<180; i=i+5){
            servo.write(i);
            delay(1666);
            }
      
        long timeNow = millis();
        long timeElapsed = timer-timeNow;
        
        if (timeElapsed<(1000*60*0.33)){
            digitalWrite(ledGreen, HIGH);
            digitalWrite(ledYellow, LOW);
            digitalWrite(ledRed, LOW);
        }
        else if(timeElapsed<(1000*60*0.66)){
            digitalWrite(ledGreen, LOW);
            digitalWrite(ledYellow, HIGH);
            digitalWrite(ledRed, LOW);
        }
        else{
            digitalWrite(ledGreen, LOW);
            digitalWrite(ledYellow, LOW);
            digitalWrite(ledRed, HIGH);
        }
    }

}
Click to Expand
x
Share this Project

This project is only accessible by signed in users. Be considerate and think twice before sharing.



About

* get to know the actuators you can use to create compelling outputs and interactivity
* learn how to program the behavior of movement using servos, fans or solenoids to create interactivity and communicate information
* explore cloud functions as a way to quickly prototype and simulate online data.
* explore actuators and the kinds of opportunities they might create for your second project.
* to structure changes and transitions in code