I have a windows computer connected to my Arduino Uno. I work in a area with a bunch of cubicles and we leave our desk fairly regularly to go and troubleshoot other computers (I'm a service desk technician). When we leave we are instructed to raise and lower a small flag so management can see whether or not we are sitting at our desk. I've attached my arduino to a servo motor with the following code.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define servoPin 3 //~
#define pushButtonPin 2
int angle =0; // initial angle for servo
int angleStep =20;
const int minAngle = 0;
const int maxAngle = 90;
int buttonPushed =0;
void setup() {
// Servo button demo by Robojax.com
Serial.begin(9600); // setup serial
myservo.attach(servoPin); // attaches the servo on pin 3 to the servo object
pinMode(pushButtonPin,INPUT_PULLUP);
Serial.println("Nathan's Status flag");
}
void loop() {
if(digitalRead(pushButtonPin) == LOW){
buttonPushed = 1;
}
if( buttonPushed ){
// change the angle for next time through the loop:
angle = angle + angleStep;
// reverse the direction of the moving at the ends of the angle:
if (angle <= minAngle || angle >= maxAngle) {
angleStep = -angleStep;
buttonPushed = 0;
}
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
delay(100); // waits for the servo to get there
}
}
We also have a policy that we need to keep our computers locked for obvious reasons. I learned my lesson with that early on. I would like to edit my code so that when I lock my computer the flag goes down, then when my computer is unlocked it goes back up. That way as long as I remember to keep my computer locked when I'm away I don't have to worry about the flag. Here is my breadboard/arduino layout.
I also have processing on my computer and am planning on using that. (https://processing.org/)
Any help is greatly appreciated.