PDA

View Full Version : First Program with arduinno



nolimit44
01-29-2011, 12:02 PM
hi, i was wondering if someone would be able to help me. my goal in mind is that i am creating a pair of robotic eyes that i would like to have the leds in the eyes blink at random intervals and randoms times per blink as well as to have them move left and right at the same random intervals and speed. this is going from a 12 volt source to the seeeduino then from seeeduino to brick and the brick will go out to 2 push buttons which will be used to turn on and turn off both the eye movements and the leds in the eyes. The servo will be on a connecting rod with the eyes and will generate the movement. i have purchased the following

Item : 36 Inch PWM Signal Booster Cable
Item : Electronic Brick - Half Buckled 3 Wire Cable - 5 Pack
Item : JST 2 Pin Power Connector
Item : (2) Electronic Brick - Mini Push Button
Item : Seeeduino V2.2 (Atmega 328P)
Item : Electronic Brick Shield V4
Item : 25W Step down adjustable switching regulator

i was wondering if these codes will work and if so can someone help me combine the two codes as well as incoporate the 2 push buttons to control the power on and off of the leds for one and the movement for the other. thanks, here is the code

#include <Servo.h> //include the servo libary - a bunch of code for a host of servo instructions y9ou can use and don't have to develop yourself

Servo myservo; // create servo object to control a servo

int pos = 0; // variable to store the servo position
int delay1 = 0; // variable to store the delay between servo arm's movement info

void setup()
{
myservo.attach(9); // attaches pin 9 of the micro controller to the servo object - the servo's "control wire"
}

void loop()
{
pos=random(65,115); // ramdomly set the servo arm postion between 65 & 115 degrees. "90" is "straight ahead"
delay1=random(50, 500); // randomly set delay between servo movement between 50 and 500 milliseconds
myservo.write(pos); // tell servo to go to position specified by variable ‘pos’ value
delay(delay1); // waits randomly between 50ms and 500 ms between servo movements
}

heres the code for the leds

/*
* Blink_Randomly
*
* Modified from the basic Arduino example. Turns an LED on for a random time,
* then off for a (most likely) different random time. We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* Original at - http://www.arduino.cc/en/Tutorial/Blink (http://www.arduino.cc/en/Tutorial/Blink)
*/

int ledPin = 13; // LED connected to digital pin 13
long randOn = 0; // Initialize a variable for the ON time
long randOff = 0; // Initialize a variable for the OFF time


void setup() // run once, when the sketch starts
{
randomSeed (analogRead (0)); // randomize
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void loop() // run over and over again
{
randOn = random (100, 1200); // generate ON time between 0.1 and 1.2 seconds
randOff = random (200, 900); // generate OFF time between 0.2 and 0.9 seconds
digitalWrite(ledPin, HIGH); // sets the LED on
delay(randOn); // waits for a random time while ON
digitalWrite(ledPin, LOW); // sets the LED off
delay(randOff); // waits for a random time while OFF
}



.AOLWebSuite .AOLPicturesFullSizeLink { height: 1px; width: 1px; overflow: hidden; } .AOLWebSuite a {color:blue; text-decoration: underline; cursor: pointer} .AOLWebSuite a.hsSig {cursor: default}