-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathToy Story
146 lines (130 loc) · 4.29 KB
/
Toy Story
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// display the score board and the LDR sensors on 9 different aliens
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
#define TEST_DELAY 1000
#define ldrpin1 A7
#define ldrpin2 A8
#define ldrpin3 A9
#define ldrpin4 A10
#define ldrpin5 A11
#define ldrpin6 A12
#define ldrpin7 A13
#define ldrpin8 A14
#define ldrpin9 A15
int threshold = 550;
int i=0;
TM1637Display display(CLK, DIO);
void setup() {
// put your setup code here, to run once:nxzzn
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
display.setBrightness(0x0f);
display.showNumberDec(i, false); // Expect: ___0
delay(TEST_DELAY);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("LDR 1 reading:");
Serial.println(analogRead(ldrpin1));
Serial.print("LDR 2 reading:");
Serial.println(analogRead(ldrpin2));
Serial.print("LDR 3 reading:");
Serial.println(analogRead(ldrpin3));
Serial.print("LDR 4 reading:");
Serial.println(analogRead(ldrpin4));
Serial.print("LDR 5 reading:");
Serial.println(analogRead(ldrpin5));
Serial.print("LDR 6 reading:");
Serial.println(analogRead(ldrpin6));
Serial.print("LDR 7 reading:");
Serial.println(analogRead(ldrpin7));
Serial.print("LDR 8 reading:");
Serial.println(analogRead(ldrpin8));
Serial.print("LDR 9 reading:");
Serial.println(analogRead(ldrpin9));
if(analogRead(ldrpin1)>=threshold||analogRead(ldrpin2)>=threshold||analogRead(ldrpin3)>=threshold||analogRead(ldrpin4)>=threshold||analogRead(ldrpin5)>=threshold||analogRead(ldrpin6)>=threshold||analogRead(ldrpin7)>=threshold||analogRead(ldrpin8)>=threshold||analogRead(ldrpin9)>=threshold){
i++;
display.showNumberDec(i, false);
delay(TEST_DELAY);
}
}
// control the 9 servo that is attached to the aliens
#include <Servo.h>
#include <Wire.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
Servo servo7;
Servo servo8;
Servo servo9;
// create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
servo1.attach(2);
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
servo6.attach(7);
servo7.attach(8);
servo8.attach(9);
servo9.attach(10);
// attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 80; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo2.write(pos);
servo5.write(pos);
servo9.write(pos);
// tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 80; pos >= -10; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo2.write(pos);
servo5.write(pos);
servo9.write(pos);
// tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 80; pos += 1) { // goes from 180 degrees to 0 degrees
servo3.write(pos);
// tell servo to go to position in variable 'pos'
servo4.write(pos);
servo7.write(pos);
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 80; pos >= -10; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo3.write(pos);
// tell servo to go to position in variable 'pos'
servo4.write(pos);
servo7.write(pos);
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 80; pos += 1) { // goes from 180 degrees to 0 degrees
servo1.write(pos);
servo6.write(pos);
servo8.write(pos);
// tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
for (pos = 80; pos >= -10; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo1.write(pos);
servo6.write(pos);
servo8.write(pos);
// tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
// waits 15ms for the servo to reach the position
}