// Code for button control of the servo/rotating table, as well as the calibration function.
int servoPin = A0;
int button1 = A1;
int button1State;
int button2 = A2;
int button2State;
int button3 = A7;
int button3State;
int rotPos = 1;
void setup(){
pinMode(servoPin, OUTPUT);
pinMode(D0, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
Spark.variable("button1", &button1State, INT);
Spark.variable("button2", &button2State, INT);
Spark.variable("button3", &button3State, INT);
}
void loop(){
button1State = analogRead(button1);
button2State = analogRead(button2);
button3State = analogRead(button3);
if (button1State > 3000){
delay(500);
button1State = analogRead(button1);
if (button1State < 3000){
if (rotPos == 2){
analogWrite(servoPin, 250);
delay(1600);
analogWrite(servoPin, 0);
rotPos = 1;
}else if(rotPos == 3){
analogWrite(servoPin, 250);
delay(800);
analogWrite(servoPin, 0);
rotPos = 1;
}else if(rotPos == 1){
analogWrite(servoPin, 0);
}
else{
analogWrite(servoPin,0);
rotPos = 3;
}
}
delay(1500);
if (button1State > 3000){
calibrate1();
//function that calibrates bin
}
}
else if (button2State > 3000){
delay(500);
button2State = analogRead(button2);
if (button2State < 3000){
if (rotPos == 3){
analogWrite(servoPin, 250);
delay(1600);
analogWrite(servoPin, 0);
rotPos = 2;
}
else if(rotPos == 1){
analogWrite(servoPin, 250);
delay(800);
rotPos = 2;
analogWrite(servoPin, 0);
}
else if(rotPos == 2){
analogWrite(servoPin, 0);
}
else{
analogWrite(servoPin,0);
rotPos = 3;
}
}
delay(1500);
if (button2State > 3000){
calibrate2();
//function that calibrates bin
}
}
else if (button3State > 3000){
delay(500);
button3State = analogRead(button3);
if (button3State < 3000){
if (rotPos == 1){
analogWrite(servoPin, 250);
delay(1600);
analogWrite(servoPin, 0);
rotPos = 3;
}else if(rotPos == 2){
analogWrite(servoPin, 250);
delay(800);
analogWrite(servoPin, 0);
rotPos = 3;
}else if(rotPos == 3){
analogWrite(servoPin, 0);
}
else{
analogWrite(servoPin,0);
rotPos = 3;
}
}
delay(1500);
if (button3State > 3000){
calibrate3();
//function that calibrates bin
}
}
else{}
}
void calibrate1(){
Spark.publish("IOTFinal15calibrate", "a");
digitalWrite(D0, HIGH);
delay(100);
digitalWrite(D0, LOW);
delay(100);
digitalWrite(D0, HIGH);
delay(100);
digitalWrite(D0, LOW);
delay(100);
digitalWrite(D0, HIGH);
delay(100);
digitalWrite(D0, LOW);
}
void calibrate2(){
}
void calibrate3(){
}
// Code for LED display for amount of material in drawer.
const int ledTotal = 10;
int ledPins[] = {D0, D1, D2, D3, D4, D5, D6, D7, A0, A1}; // an array of pin numbers to which LEDs are attached
void setup() {
// loop over the pin array and set them all to output:
for (int i = 0; i < ledTotal; i++) {
pinMode(ledPins[i], OUTPUT);
}
// loop over the pin array and set them all to output:
for (int i = 0; i < ledTotal; i++) {
digitalWrite(ledPins[i], HIGH);
}
}
void loop() {
delay(100);
}
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. .