• Yes-No Thing

    01/03/2016 at 21:58 0 comments

    An electronic excise and a table piece made for a themed party. A basic exercise in physical input-output using a servo logic. A breadboard with a servo, joystick, arduino nano, and a usb-to-serial adapter all sitting on a usb charger. A very short arduino code.

    //
    // Yes-No
    // wp
    //
    // arduino nano - servo - joystick
    //
    // servo input -> D2
    // joystick axis -> A1
    //
    
    #include <Servo.h>
    
    Servo myservo;        // create servo object 
    
    int pos = 0;          // servo position
    const int joyH = 1;   // pin A1 for joystick axis
    
    void setup() {
      myservo.attach(2);  // attaches the servo on pin D2 
      Serial.begin(9600);
    }
    
    void loop() {
      pos = analogRead(joyH);           
      pos = map(pos, 0, 1023, 0, 180);  // rescale joystk value
      myservo.write(pos);               // command the servo
      delay(15);                        // time for servo mvmt
    }