In our first discussion/brainstorm our team centered on the idea of a profiling machine. The machine would take the form of a dial controlled by a servo that points to right or wrong answers.
The first idea was to control the servo angles using discrete push buttons.
This failed miserably.
Code:
/*A Moral technology by Breadboards are us
this code combines an Alternating switch program with a servo
position program to create an (im)moral profiling machine*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; //variable to store the servo position
int switchPin1 = 1; //switch is connected to pin 1
int vaLone; //variable for reading the pin status
int buttonState1; //variable to hold the last buttonState
int switchPin2 = 2; //switch is connected to pin 2
int vaLtwo; //variable for reading the pin status
int buttonState2; //variable to hold the last buttonState
void setup()
{
myservo.attach(9); // attaches servo on pin 9 to the servo object
pinMode(switchPin1,INPUT); //Set the switch pin as input
pinMode(switchPin2,INPUT); //Set the switch pin as input
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState1 = digitalRead(switchPin1); // read the initial state
buttonState2 = digitalRead(switchPin2); // read the initial state
}
void loop()
{
vaLone = digitalRead(switchPin1); //read input value and store it in val
//if (vaLone != buttonState1) { //the button state has changed!
if (vaLone == HIGH) { // check if the button is pressed
pos = 10;
myservo.write(pos); //if it's pressed send it to angle 20
}
else { //the button is not pressed
pos = 0;
myservo.write(pos);
}
buttonState1 = vaLone; // save the new state in button's variable
vaLtwo = digitalRead(switchPin2); //read input value and store it in val
//if (vaLtwo != buttonState2) { //the button state has changed!
if (vaLtwo == HIGH) { // check if the button is pressed
pos = 180;
myservo.write(pos); //if it's pressed send it to angle 20
}
else { //the button is not pressed
pos = 0;
myservo.write(pos);
}
buttonState2 = vaLtwo; //save the new state in button's variable
}
Images:
No comments:
Post a Comment