iron man eyes
so working on iron man helmet , want eyes ligt when helmet closes,
i have 2 servo's in helmet , want add lights it.
can me??
i have 2 servo's in helmet , want add lights it.
can me??
for short programs please include them in post don't have download them. time.
and if need attach longer program please attach .ino file
...r
code: [select]
#include <servo.h>
servo myservo; // create servo object control servo
servo myservo2; // create 2nd servo object control 2nd servo
// constant won't change:
const int buttonpin = 2; // pin pushbutton attached to
// variables change:
int buttonstate = 0; // current state of button
int lastbuttonstate = 0; // previous state of button
int buttonpushcounter = 0; // counter number of button presses
boolean currentbutton = low;
void setup() {
// attach servo pins
myservo.attach(9);
myservo2.attach(10);
// tell servo go position in variable 'pos'
myservo.write(0);
myservo2.write(0);
delay(15);
// initialize button pin input:
pinmode(buttonpin, input);
}
boolean debounce(boolean last)
{
boolean current = digitalread(buttonpin);
if (last != current)
{
delay(5);
current = digitalread(buttonpin);
}
return current;
}
void loop() {
// read pushbutton input pin:
buttonstate = debounce(buttonpin);
// compare buttonstate previous state
if (buttonstate != lastbuttonstate) {
// if state has changed, increment counter
if (buttonstate == high) {
// if current state high button
// went off on:
buttonpushcounter++;
}
else {
}
// save current state last state,
//for next time through loop
lastbuttonstate = buttonstate;
}
// moves servo every other button push
// checking modulo of button push counter.
// modulo function gives remainder of
// division of 2 numbers:
if (buttonpushcounter % 2 == 0) {
//move position 90
myservo.write(180);
myservo2.write(0);
delay(15);
} else {
//or: move position 0
myservo.write(0);
myservo2.write(180 );
delay(15);
}
}
and if need attach longer program please attach .ino file
...r
Arduino Forum > Using Arduino > Project Guidance > iron man eyes
arduino
Comments
Post a Comment