-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaladevelopMostUselessMachine.c
More file actions
61 lines (50 loc) · 1.46 KB
/
DaladevelopMostUselessMachine.c
File metadata and controls
61 lines (50 loc) · 1.46 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
/*
Karl-Henrik Nilsson - Daladevelop hackaton 2015
This code is inteded to be used to control the "off switch arm" of the "Usless machine" design that were lasercut at the Hackatons arranged by Soltorgsgymnasiet and Daladevelop.
This code is inteded to be used with the Arduino UNO.
The switch needs to be connected to PIN12 and PIN13. The switch should have a pulldown (connection to GND) of 10K Ohm on the side that is connected to PIN12.
The servo signal is on PIN 9.
*/
#include <Servo.h>
//Make changes to pin selections here.
#define switchPin 13
#define vPin 12 // +5V for the switch due to lack of +5v outputs.
#define servoSignalPin 9
Servo myservo; // The servo object - this allows us to control the servo.
int pos = 0; // The variable that holds the servo position
void setup()
{
pinMode(switchPin,INPUT);
pinMode(vPin,OUTPUT);
myservo.attach(servoSignalPin); // attaches the servo on pin 9 to the servo object
myservo.write(pos);
delay(15);
digitalWrite(vPin,1);
}
void loop()
{
if(digitalRead(switchPin) == 1)
{
while(pos <= 130)
{
if(digitalRead(switchPin) == 0)
{
break;
}
myservo.write(pos += 10);
delay(50);
}
}
if(digitalRead(switchPin) == 0)
{
while(pos > 0)
{
if(digitalRead(switchPin) == 1)
{
break;
}
myservo.write(pos -= 10);
delay(50);
}
}
}