Go Down

Topic: ++ SOLVED ++array label question (Read 581 times) previous topic - next topic

ArduinoPat

Dear Jimmy60,

Many thanks for your reply , this is the way i want 

It's clear now what i did wrong ,

all works fine now , i have only exchange the follow command:

if(digitalRead(inputPins[index]) == LOW)   

in stead of HIGH i put this in LOW ,
In HIGH the LED was ligthing continue , when i exchange this in LOW , I push the button and the LED will on.

Also many thanks to PaulS  :)

http://www.youtube.com/watch?v=1j2CZlD3onw

Best Regards,

Patrick , Maarssen The Netherlands
Patrick ,The Netherlands

ArduinoPat

#6
Aug 10, 2012, 11:07 am Last Edit: Aug 10, 2012, 04:46 pm by ArduinoPat Reason: 1
Dear All,

all works well , but now i have adjust this sketch to an I2C LCD,
All works fine but after pushing the last button action , the text shows at the LCD and will not clear.

So when i push the Yellow button , the LCD display continue show Yellow pressed.

I have try it with lcd.clear at the end of this sketch , but then the LCD will continue empty , also during pushing the buttons ????

http://www.youtube.com/watch?v=mHO_VeuHI20

Code: [Select]
char *switchPinNames[] = {
 "Red switch", "Green switch", "Yellow switch"};
char *ledPinNames[] = {
 "Red ", "Green", "Yellow"};
int inputPins[] = {
 2,3,4,5};  // create an array of pins for switch inputs
int ledPins[] = {
 10,11,12,13};  // create array of output pins for LEDs

// I2C LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


void setup()
{
lcd.init();                      // initialize the lcd

 // Print a message to the LCD.
 lcd.backlight();

 
 for(int index = 0; index < 4; index++)
 {
   pinMode(ledPins[index], OUTPUT);         // declare LED as output
   pinMode(inputPins[index], INPUT);        // declare pushbutton as input
   digitalWrite(inputPins[index],HIGH);     // enable pull-up resistors
   //(see Recipe 5.2)
 }
}

void loop(){
 for(int index = 0; index < 4; index++)
 {

   if(digitalRead(inputPins[index]) == LOW)
   {
     digitalWrite(ledPins[index], HIGH);
     lcd.setCursor(0, 0);
     lcd.print(ledPinNames[index]);
     lcd.print(" Pressed,   ");
   }    
   else
   {
     digitalWrite(ledPins[index], LOW);      // turn LED off
     lcd.clear();  //this will not work !!!! LCD keeps empty !!!
   
   }
 }
}


lcd.clear();  //this will not work !!!! LCD keeps empty !!!

Regards,

Patrick , ArduinoPat , The Netherlands.
Patrick ,The Netherlands

ArduinoPat

#7
Aug 10, 2012, 04:49 pm Last Edit: Aug 10, 2012, 09:25 pm by ArduinoPat Reason: 1
All works well now !!

all i had to do is the follow line:

lcd.print("                            ");

that was all  :smiley-fat:

Find attached the correct working sketch:

Code: [Select]
char *switchPinNames[] = {
  "Red switch", "Green switch", "Yellow switch"};
char *ledPinNames[] = {
  "Red ", "Green", "Yellow"};
int inputPins[] = {
  2,3,4,5};  // create an array of pins for switch inputs
int ledPins[] = {
  10,11,12,13};  // create array of output pins for LEDs

// I2C LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


void setup()
{
   lcd.init();
   lcd.backlight();
   
   
  for(int index = 0; index < 4; index++)
 

 
  {
    pinMode(ledPins[index], OUTPUT);         // declare LED as output
    pinMode(inputPins[index], INPUT);        // declare pushbutton as input
    digitalWrite(inputPins[index],HIGH);     // enable pull-up resistors
    //(see Recipe 5.2)
  }
}

void loop(){
   
    for(int index = 0; index < 4; index++)
  {   

    if(digitalRead(inputPins[index]) == LOW)
    {

     
      digitalWrite(ledPins[index], HIGH);
      lcd.setCursor(0, 0);
      lcd.print(ledPinNames[index]);
      lcd.print(" Pressed,   ");
    }   
    else
    {
      digitalWrite(ledPins[index], LOW);      // turn LED off
      lcd.print("                ");
    }
  }
}



Best Regards , ArduinoPat , The Netherlands
Patrick ,The Netherlands

Go Up