Author Topic: Programming the Roboduino  (Read 1376 times)

0 Members and 1 Guest are viewing this topic.

Offline I Am BlashyrkhTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Programming the Roboduino
« on: April 25, 2009, 10:35:51 PM »
Ive been following the tutorial for the roboduino and the $50 dollar robot but Im having issues that I think are programming issues.
So heres my question. When I got my roboduino board I tested my servos with the arduino software and it worked fine. Could I just copy the code into the arduino software or could I just open the hex file i was working with in avr studio in arduino and upload it that way? Would that work?
or if not, does anyone know of a basic photovore code (two resistors, two servos) that can be used with the arduino software? Alas! I am running out of time! Anyone who can help in any way it would be much appreciated.

Offline billhowl

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 32
  • Your success is in your hands.
Re: Programming the Roboduino
« Reply #1 on: April 27, 2009, 10:32:41 AM »
Here is the code that can just copy into arduino IDE




/****************************************************************************
*
*   Copyright (c) 2007 www.societyofrobots.com
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
*   Photovore v1.01, April 27th, 2009
*   Simple case-based method for a robot that chases light.
*   modified to run in Arduino IDE
*    http://www.arduino.cc/
*
*
****************************************************************************/

#include <Servo.h>

Servo servo_left;   // create servo object to control a servo
                    // a maximum of eight servo objects can be created
Servo servo_right;  // create servo object to control a servo

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{

  servo_left.attach(9);  // attaches the servo on pin 9 to the servo object
  servo_right.attach(10);  // attaches the servo on pin 10 to the servo object
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output

}
 
   int sensor_left=0;//left photoresistor
   int sensor_right=0;//right photoresistor
   int threshold=8;//the larger this number, the more likely your robot will drive straight
   
void loop()
{
   digitalWrite(ledPin, HIGH);   // sets the LED on
//store sensor data
   sensor_left = analogRead(0);            // reads the value of the left photoresistor (value between 0 and 1023)
   sensor_left = map(sensor_left, 0, 1023, 0, 255);     // scale it to use it with the 8bits (value between 0 and 255)
   sensor_right = analogRead(1);            // reads the value of the right photoresistor (value between 0 and 1023)
   sensor_right = map(sensor_right, 0, 1023, 0, 255);     // scale it to use it with the 8bits (value between 0 and 255)

      //detects more light on left side of robot
      if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)
         {//go left
         servo_left.write(0);     
         servo_right.write(150);
         }

      //detects more light on right side of robot
      else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
         {//go right
         servo_left.write(150);
         servo_right.write(0);
         }
         
      //detects no light on both left and right side of robot
      else if(sensor_right == sensor_left && (sensor_right - sensor_left) < threshold)
         {//go right
         servo_left.write(90);
         servo_right.write(90);
         }

      //light is about equal on both sides
      else
         {//go straight
         servo_left.write(150);
         servo_right.write(150);
         }
   delay(25);                       // waits 25ms for a small delay to prevent crazy oscillations    
   digitalWrite(ledPin, LOW);    // sets the LED off   
}


hope it work for you :)


 


Get Your Ad Here