View unanswered posts | View active topics It is currently Fri Jul 25, 2014 11:58 am






Reply to topic  [ 1 post ] 
Help with finishing simple code BOE Bot 
Author Message
Rookie

Joined: Wed Jun 11, 2014 4:15 pm
Posts: 1
Post Help with finishing simple code BOE Bot
I have a BOE Bot with arduino and I'm trying to program it via ROBOTC to use the light chasing sensors and also flash the led lights while it is going. I was looking to put the speaker in too for sound but I don't know how to do that. My problem is the light sensors and the LED Lights both say task main () so they won't work simultaneously on the bot. I keep getting the error message - **Error**:Duplicate definition for task 'main'. I have pasted my whole code below. Thank you!

Code:
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(PluginCircuitBoard, typeShieldParallaxBoeBot)
#pragma config(Sensor, anlg0,  leftLight,      sensorReflection)
#pragma config(Sensor, anlg1,  rightLight,     sensorReflection)
#pragma config(Sensor, dgtl5,  led1,           sensorDigitalOut)
#pragma config(Sensor, dgtl6,  led2,           sensorDigitalOut)
#pragma config(Motor,  servo_10,        leftServo,     tmotorServoContinuousRotation, openLoop, IOPins, dgtl10, None)
#pragma config(Motor,  servo_11,        rightServo,    tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl11, None)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

 task main()
{
  while(true)
  {
    int factor = 120; //This value worked for us however you might want to change it for your robot/flashlight intensity.
    int shadeDiff = ((SensorValue[rightLight] * factor) / (SensorValue[leftLight] + SensorValue[rightLight]) - (factor / 2)) * 2;
 
    motor[leftServo] = 20 + shadeDiff;
    motor[rightServo] = 20 - shadeDiff;
 
    //If the loop cycles too quickly, we get calculation errors. Therefore we regulate the speed by waiting a bit.
    wait1Msec(10);
  }
 
}

task main()
{
  while(true) //repeat indefinitely
  {
    //turn led1 on
    SensorValue[led1] = true;

    //turn led2 off
    SensorValue[led2] = false;

    //wait 1 second
    wait1Msec(300);

    //turn the led1 off
    SensorValue[led1] = false;

    //turn led2 on
    SensorValue[led2] = true;

    //wait 1 second
    wait1Msec(300);
  }
}


Wed Jun 11, 2014 4:51 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.