Issuu on Google+

NottingHACK 2.0

Lincoln Hackspace

HACKSPACES

NottingHACK 1.0 (not depicted in plans)

London Hackspace Ground Floor

London Hackspace Basement Floor BioLab and Workshops

London Hackspace Basement Floor Storage


if (pushButton2State == 1) turnYellow(2); delay(1000); turnRed(2); potState2 = analogRead(A1);

pushButton2State = digitalRead(pushButton2);

}

else { digitalWrite(redLed2, LOW); digitalWrite(yellowLed2, LOW); digitalWrite(greenLed2, HIGH); }

void turnGreen(int trafficLightNumber){ if (trafficLightNumber == 1){ digitalWrite(redLed1, LOW); digitalWrite(yellowLed1, LOW); digitalWrite(greenLed1, HIGH); }

turnGreen(2);

}

delay(1000); }

else { digitalWrite(redLed2, HIGH); digitalWrite(yellowLed2, HIGH); digitalWrite(greenLed2, LOW); }

void turnRedNYellow(int trafficLightNumber){ if (trafficLightNumber == 1){ digitalWrite(redLed1, HIGH); digitalWrite(yellowLed1, HIGH); digitalWrite(greenLed1, LOW); }

}

else { digitalWrite(redLed2, HIGH); digitalWrite(yellowLed2, LOW); digitalWrite(greenLed2, LOW); }

void turnRed(int trafficLightNumber){ if (trafficLightNumber == 1){ digitalWrite(redLed1, HIGH); digitalWrite(yellowLed1, LOW); digitalWrite(greenLed1, LOW); }

}

else { digitalWrite(redLed2, LOW); digitalWrite(yellowLed2, HIGH); digitalWrite(greenLed2, LOW); }

turnRedNYellow(1);

}

while (potState1 != pot1endPoint){ potState1 = analogRead(A0);

else { pot1endPoint = 0; }

if (pushButtonState1 == 1) { turnYellow(1); delay(1000); turnRed(1); potState1 = analogRead(A0); if (potState1 < 512){ pot1endPoint = 1023; }

pushButtonState1 = digitalRead(pushButton1);

turnGreen(1);

void loop() {

}

pinMode(pushButton1, INPUT); pinMode(pushButton2, INPUT);

pinMode(redLed1, OUTPUT); pinMode(yellowLed1, OUTPUT); pinMode(greenLed1, OUTPUT); pinMode(redLed2, OUTPUT); pinMode(yellowLed2, OUTPUT); pinMode(greenLed2, OUTPUT);

setup() {

void turnYellow(int trafficLightNumber){ if (trafficLightNumber == 1){ digitalWrite(redLed1, LOW); digitalWrite(yellowLed1, HIGH); digitalWrite(greenLed1, LOW); }

boolean pot1endPoint = LOW; boolean pot2endPoint = LOW;

delay(1000); }

turnRedNYellow(2);

}

)

if (potState2 < 512){ pot2endPoint = 1023; } else { pot2endPoint = 0; } while (potState2 != pot2endPoint){ potState2 = analogRead(A1); }

int potState1 = 0; int potState2 = 0;

int pushButtonState1 = 0; int pushButton2State = 0;

int pushButton1 = 9; int pushButton2 = 5;

int redLed2 = 8; int yellowLed2 = 7; int greenLed2 = 6;

int redLed1 = 12; int yellowLed1 = 11; int greenLed1 = 10;

ARDUINO CODING

Week 2: 19/02/14 Writing a programme for controlling two sets of traffic lights at once

if(results.value==numPad1){ posSend[currentPosSendIndex]=1; currentPosSendIndex=currentPosSendIndex+1;

if(results.value==numPad0){ posSend[currentPosSendIndex]=0; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad0 || results.value==numPad1 || results.value==numPad2 || results.value==numPad3 || results.value==numPad4 || results.value==numPad5 || results.value==numPad6 || results.value==numPad7 || results.value==numPad8 || results.value==numPad9 ){

if(irrecv.decode(&results)){

myServo.write(currentPos);

if (currentPos>160){ currentPos=160; Serial.print("Corrected position is now: "); Serial.println(currentPos); }

}

if(currentPosSendIndex>2){ currentPosSendIndex=0; posSend[0]=0; posSend[1]=0; posSend[2]=0;

void loop(){

}

myServo.attach(9); Serial.begin(9600); irrecv.enableIRIn();

void setup(){

int posSend[]={0,0,0}; int currentPosSendIndex=0; int calculatedPosSendValue=0;

#define numPad0 0x20DF08F7 #define numPad1 0x20DF8877 #define numPad2 0x20DF48B7 #define numPad3 0x20DFC837 #define numPad4 0x20DF28D7 #define numPad5 0x20DFA857 #define numPad6 0x20DF6897 #define numPad7 0x20DFE817 #define numPad8 0x20DF18E7 #define numPad9 0x20DF9867 #define enterButton 0x20DF22DD

Servo myServo; int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); int currentPos = 90; decode_results results;

#include<IRremote.h> #include<Servo.h>

}

delay (100); irrecv.resume(); }

Serial.print("Arjun, the current position of the servo is: "); Serial.println(currentPos);

else if (results.value==enterButton){ currentPos=calculatedP`osSendValue; currentPosSendIndex=3; }

Serial.print("Arjun, the current position ready to send is: "); Serial.println(calculatedPosSendValue); }

calculatedPosSendValue=((posSend[0]*100)+(posSend[1]*10)+(posSend[2]*1));

if(results.value==numPad9){ posSend[currentPosSendIndex]=9; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad8){ posSend[currentPosSendIndex]=8; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad7){ posSend[currentPosSendIndex]=7; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad6){ posSend[currentPosSendIndex]=6; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad5){ posSend[currentPosSendIndex]=5; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad4){ posSend[currentPosSendIndex]=4; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad4){ posSend[currentPosSendIndex]=4; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad3){ posSend[currentPosSendIndex]=3; currentPosSendIndex=currentPosSendIndex+1; }

if(results.value==numPad2){ posSend[currentPosSendIndex]=2; currentPosSendIndex=currentPosSendIndex+1; }

}

Weeks 3/4: 26/02/14 - 05/03/14 Arduino sketch for controlling range of movement (in degrees) of a servo motor using input buttons on a television remote


Hackspace compilation