-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab03automaticmode.ino
More file actions
63 lines (58 loc) · 1.36 KB
/
lab03automaticmode.ino
File metadata and controls
63 lines (58 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *mymotor = AFMS.getMotor(1);
const int switchPin = 7;
int switchState;
int sensorValue;
const int sensorPin = A0;
int count ;
int turns = 0;
boolean running=true;
void setup(){
//set up motor and serial monitor
Serial.begin(9600);
AFMS.begin();
mymotor->setSpeed(200);
mymotor->run(RELEASE);
}
void loop(){
switchState = digitalRead(switchPin);
//currentmillis = millis();
if (running && switchState == 0){
//if not in locked position
mymotor->setSpeed(200);
mymotor->run(FORWARD);
count = 0;
}
else if(running) {
//if in locked position
if(count == 0){
//pause the first time it reaches locked
mymotor->setSpeed(0);
mymotor->run(FORWARD);
delay(500);
sensorValue = analogRead(sensorPin);
//scan the petri dish and display results
if (sensorValue <= 400){
Serial.println("This petri dish is occupied with material");
}
else{
Serial.println("This petri dish is empty");
}
delay(500);
turns++;
count=+1;
}
//move on to the next plate
mymotor->setSpeed(200);
mymotor->run(FORWARD);
}
if (turns >= 4){
//stop after all petri dishes are scanned.
mymotor->setSpeed(0);
mymotor->run(FORWARD);
running=false;
}
}