User Tools

Site Tools


laser_tripwire_rubber_band_shooter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
laser_tripwire_rubber_band_shooter [2018/08/08 17:01]
glassgiant
laser_tripwire_rubber_band_shooter [2018/08/09 16:38]
glassgiant [Arduino Code]
Line 8: Line 8:
 {{:​workshops:​rubber_band_shooter:​511968d9ce395f7c54000000.png?​400|}} {{:​workshops:​rubber_band_shooter:​511968d9ce395f7c54000000.png?​400|}}
  
 +====== Arduino Code ======
 +<code c>
 +#include <​Servo.h>​
  
 +
 +int lightPin = A0;  //define a pin for Photo resistor
 +int ledPin=13; ​    //​define a pin for LED
 +int threshold = 800; //define threshold value. Below this, the beam is assumed to be broken
 +int servoPin = 11;  //define a pin for the servo
 +int fireposition = 40;
 +int homeposition = 150;
 +
 +Servo myservo;
 +
 +void setup()
 +{
 +    Serial.begin(9600); ​ //Begin serial communcation
 +    pinMode( ledPin, OUTPUT );
 +    myservo.attach(servoPin); ​
 +    myservo.write(homeposition); ​ //move servo to home position
 +    delay(10000); ​  //10 second delay at startup ​
 +}
 +
 +void loop()
 +{
 +   ​myservo.write(homeposition);​
 +   ​delay(1000);​
 +   while (analogRead(lightPin) > threshold){
 +     ​Serial.println(analogRead(lightPin));​ //Write the value of the photoresistor to the serial monitor.
 +     ​digitalWrite(ledPin,​ 1);
 +     ​delay(10);​
 +   }
 +   ​myservo.write(fireposition);​
 +   ​digitalWrite(ledPin,​ 0);
 +   ​delay(1000);​
 +}
 +</​code>​
laser_tripwire_rubber_band_shooter.txt · Last modified: 2018/08/09 16:38 by glassgiant