Pages: [1]   Go Down
Author Topic: Using a photoresistor to block menu with arduino!  (Read 552 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys!
Im doing a project in school where im using a menu on an LCD display and four buttons to navigate. The microcontroler im using is Arduino. I got the program for the LCD from http://www.coagula.org/content/pages/tutorial-manage-menu-and-lcd-display-arduino, and it is working perfectly! But i want to combine it with a photoresistor, so when i press a button and the value is to high, the screen will say "Make the room darker" or something like that. And if the value is low enough it will proceede to submenus.

Thanks!  smiley
« Last Edit: November 16, 2012, 09:50:26 am by ekarlsson25 » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8461
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hook the LDR up to an analog input, read the value and make a decision based on that value.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am pretty new to programing, but I've figured out how to read the pin. The part I'm not sure is where to place de "decisions" depending on the value. And if i should be using "if" statement.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8461
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And if i should be using "if" statement.
Yes.

For example (very roughly)

Code:
int light_level = analogRead(A0);

if (light_level < 500) {
    lcd.print ("Dark enough");
} else {
    lcd.print ("Not dark enough");
}


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help, but it's not really what im looking for.
When i press the a button on the menu, i want it to either "block" the menu and write "make it darker", but if its dark enough it will proceede to submenu.
I'm sorry if im pretty slow  smiley-confuse
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8461
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well let's make a small change

Code:
int light_level = analogRead(A0);

if (light_level < 500) {
    print_menu();
} else {
    lcd.print ("Make it darker");
}

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much! It helped alot, and now it's working  smiley
Logged

Pages: [1]   Go Up
Jump to: