-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidterm_carousel
95 lines (71 loc) · 1.69 KB
/
midterm_carousel
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//Midterm. Carousel Game
//Karina Kurmanbayeva
//DIGF2B03 Physical Computing
//OCAD University
//Feb 11, 2015
#include <Servo.h>
Servo servo360; // create servo object to control a servo
Servo servo180;
//pins
const int potpin = 0; // analog pin used to connect the potentiometer
int sensorValue;
const int buttonUP = 11;
const int ledPinUP = 10;
// button states
int buttonStateUP = 0;
// character
const int characterTouches = 3;
const int ledPinCh = 4;
int characterState = 0;
void setup()
{
servo360.attach(9);
servo180.attach(5);
pinMode(buttonUP, INPUT);
pinMode(ledPinUP, OUTPUT);
// character
pinMode(characterTouches, INPUT);
pinMode(ledPinCh, OUTPUT);
}
void loop()
{
//chatacter movement
buttonStateUP = digitalRead(buttonUP);
if (buttonStateUP == HIGH) {
CharacterUp();
}
else {
CharacterDown();
}
//gameOver
characterState = digitalRead(characterTouches);
if (characterState == LOW) {
gameOver();
}
else{
gameRotate();
}
}
void gameOver(){
digitalWrite(ledPinCh, HIGH); //turn led on
servo360.detach();
Serial.println("UP");
}
void gameRotate(){
servo360.attach(9);
sensorValue = analogRead(potpin);
sensorValue = map(sensorValue, 0, 1023, 0, 179);
servo360.write(sensorValue);
Serial.println(sensorValue);
digitalWrite(ledPinCh, LOW);
}
void CharacterUp(){
digitalWrite(ledPinUP, LOW); //turn led on
servo180.write(0);
Serial.println("UP");
}
void CharacterDown(){
servo180.write(180);
digitalWrite(ledPinUP, HIGH);
Serial.println("DOWN");
}