Skip to content

Commit

Permalink
initial version of most useless machine code for Arduino UNO
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-henrik committed Mar 5, 2015
0 parents commit ec393bf
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions DaladevelopMostUselessMachine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}

}

0 comments on commit ec393bf

Please sign in to comment.