Go Down

Topic: Using a photoresistor to block menu with arduino! (Read 701 times) previous topic - next topic

Nov 16, 2012, 03:40 pm Last Edit: Nov 16, 2012, 03:50 pm by ekarlsson25 Reason: 1
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!  :)

Graynomad

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

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

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.

Graynomad

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

Yes.

For example (very roughly)

Code: [Select]
int light_level = analogRead(A0);

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



______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

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  :~

Graynomad

Well let's make a small change

Code: [Select]
int light_level = analogRead(A0);

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


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Thank you very much! It helped alot, and now it's working  :)

Go Up