need help in programming light sensor

6 replies [Last post]
nm
Title: NooBot
Joined: 02/28/2012
Posts:
BotPoints: 3
User offline. Last seen 11 years 13 weeks ago.

hi , can you help me in programming botball because i dont know alot about C language
i need the creater move when its see the light , i tried this code but it doesnt work , can you told me what is the wrong?
// Created on Sun Feb 26 2012

#include

int main()
{

wait_for_light(0); // light sensor in analog port 0
printf("I have seen the light!\n");
printf("Drive Straight\n"); // announce the program
sleep(1.0); // wait 1 second
while (create_connect()); // Open the connection between CBC and Create
// As long as the create has not driven 1m
while (get_create_distance(0.1) < 1000)
{
create_drive_direct(250,250); // Drive forward at 250mm/sec
}
create_stop(); // Stop the Create
create_disconnect(); // Disconnect the Create
printf("All Done\n"); // Tell user program has finished
return 0;
}

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 8 years 2 weeks ago.

Hi, welcome to the Botball Community!

"It doesn't work" doesn't help in diagnosing your problem; please tell us (a) what behavior you are expecting, and (b) what behavior you are observing.

Also, please don't ask for help on the Botballer's Chat and leave less than 2 minutes later. Had you stayed in the chat longer, someone might have answered.

Thanks.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 8 years 42 weeks ago.

A couple of things. First, having a '#include' with nothing after it will give you a compile error. Removing the '#include' will fix that. Second, you shouldn't put 'create_connect' in a while loop. That line should just be 'create_connect();' Try those and see what happens.

Translation:

Remove the '#include'

change 'while (create_connect());' to 'create_connect();'

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 8 years 2 weeks ago.

I think the intention of the while loop was to retry a connection if it fails for some reason. create_connect() returns 0 on success, so that should work as intended. Seems a bit overkill to me, but maybe a useful trick if your connection is screwy.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

jiya
Title: NooBot
Joined: 06/06/2017
Posts:
BotPoints: 110
User offline. Last seen 1 year 4 weeks ago.

Light sensors have been very common nowadays. I appreciate the hard work of the students who follow the exact programming methods in order to work the light sensors. If you have any guidance, you can definitely share the details over here. cable internet speed

peterseo
peterseo's picture
Title: NooBot
Joined: 08/07/2018
Posts:
BotPoints: 60
User offline. Last seen 4 years 43 weeks ago.

I have bookmarked your website, the articles are route superior to anything other comparative web journals.. a debt of gratitude is in order for an awesome site! Green tech

Infin
Title: NooBot
Joined: 02/06/2019
Posts:
BotPoints: 2
User offline. Last seen 4 years 17 weeks ago.

In this blog many useful topics we have written for understanding programming light sensor details. So, all botball superiorpapers prepared for the community development and bot ball assignment finished programs.