Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / General Electronics / Re: PC8574 Driving LED , LOW LED Brighting on: November 11, 2012, 11:00:21 am
Thanks For Reply Both  ( Fungus and dhenry),

The code is from the Cookbook , Recipe:13.7

Code:
/*
 * I2C_7segment
 * Uses I2C port to drive a bar graph
 * Turns on a series of LEDs proportional to a value of an analog sensor.
 * see Recipe 7.5
 */

#include <Wire.h>

//address for PCF8574 with pins connected as shown in Figure 13-12
const int address = 0x38;  
const int NbrLEDs = 8;

const int analogInPin = 0; // Analog input pin connected
                           // to the variable resistor

int sensorValue = 0;       // value read from the sensor
int ledLevel = 0;          // sensor value converted into LED 'bars'
int ledBits = 0;           //  bits for each LED will be set to 1 to turn on LED

void setup()
{
  Wire.begin(); // set up Arduino I2C support
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(analogInPin);             // read the analog in value
  ledLevel = map(sensorValue, 0, 1023, 0, NbrLEDs);  // map to number of LEDs
  for (int led = 0; led < NbrLEDs; led++)
  {
    if (led < ledLevel ) {
      bitWrite(ledBits,led, HIGH);    // turn on LED if less than the level
    }
    else {
      bitWrite(ledBits,led, LOW);    // turn off LED if higher than the level
    }
    // send the value to I2C
    Wire.beginTransmission(address);
    Wire.write(ledBits);
    Wire.endTransmission();
  }
  delay(100);
}


I have tryed 1 LED with ressitor , but still te same problem ( not very bright )

Maby you have any options ?

I have tryed without the PC8574 , An=d make only a Bargraph with the Arduino,
Now the LEDS are real bright !



Thanks ,

Regards,

ArduinoPat,
32  Using Arduino / General Electronics / Re: PC8574 Driving LED , LOW LED Brighting on: November 11, 2012, 10:26:54 am
Hello Fungus,

Thanks for reply,

Ok i understand this , the PC8574 only will give a current of 100mA
But is it possible to make the LED  brighter , without damage this PC8574 ?


Best regards ,

ArduinoPat,


33  Community / Website and Forum / Re: Attached picture at TOPIC ? on: November 11, 2012, 10:15:07 am
May Thanks Rob,

I saw what i did wrong at Picasa Web,

I did not marked  "marked only "  at the Picasa web ,  smiley-confuse

But know it's working Well !!!




Best Regards,

ArduinoPat,
34  Community / Website and Forum / Re: Attached picture at TOPIC ? on: November 11, 2012, 09:30:07 am
Hello PAulS,

Thanks for quick Reply,

I know it's possible to attached a link in it like this:

https://picasaweb.google.com/lh/photo/pxPJZVbTx3nI9z2dkKaGVtbkCAJCpyZcpW83LBCi5hY?feat=directlink

But i see also some topics , direct with pictures in it ( between the text )

I hope you understand what i mean ;-))


Regards ,

ArduinoPat,
35  Using Arduino / General Electronics / PC8574 Driving LED , LOW LED Brighting on: November 11, 2012, 09:15:34 am
Dear  All,

I have did a test with the PC8574AN , Example 13.7 < COOKBOOK >

All is working well , except the brighting of the LEDS,

I saw attached that the PC8574 has a lower capacity for the LEDS than the Arduino,
How can i mnake these LEDS blinking Brighter ?


Find attached the setup of this :
https://picasaweb.google.com/lh/photo/pxPJZVbTx3nI9z2dkKaGVtbkCAJCpyZcpW83LBCi5hY?feat=directlink


Best Regards,

ArduinoPat,
36  Community / Website and Forum / Attached picture at TOPIC ? on: November 11, 2012, 09:08:55 am
Dear All,

How can i attached a picture at my Topic ?

A Video links is not the problem  ( this is working )
A image link will not work  smiley-roll-sweat


Thanks for answer this question,

ArduinoPat
37  Using Arduino / Programming Questions / Re: Sparkfun LCD Shield on: October 26, 2012, 03:03:07 pm
Dear Guix,

Many thanks for you input, but i am searching for another sketch.
I will investigate what sketch will scroll the text without background.

i appraciate you time and input for this  smiley

When i have the solution i will post it at the forum , for everybody who is interested in this

Best Regards ,

Patrick ,ArduinoPat , The Netherlands.
38  Using Arduino / Programming Questions / Re: Sparkfun LCD Shield on: October 26, 2012, 10:03:40 am
Dear Guix,

Sorry for late reply , smiley-roll

Many thank's for this sketch , but it's not the way what i mean.
But any way is it possible for only scroll the text ?
No the text scroll together with a black background , is it possible without black background and only text in the testpattern ?

Code:
#include <ColorLCDShield.h>

// Enter the time below in 12-hr format
#define HOURS 10
#define MINUTES 21
#define SECONDS 00
#define AMPM 0  // enter 0 for AM, 1 for PM

#define CLOCK_RADIUS 50  // radius of clock face
#define CLOCK_CENTER 55  // If you adjust the radius, you'll probably want to adjust this
#define H_LENGTH  30  // length of hour hand
#define M_LENGTH  40  // length of minute hand
#define S_LENGTH  48  // length of second hand

#define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
#define C_COLOR  RED  // This is the color of the clock face, and digital clock
#define H_COLOR  BLUE  // hour hand color
#define M_COLOR  GREEN  // minute hand color
#define S_COLOR  YELLOW  // second hand color

LCDShield lcd;

int hours, minutes, seconds, ampm;
int buttonPins[3] = {3, 4, 5};

unsigned long now = 0;
unsigned long time = 0;
int x = 320; //or whatever is the size of your screen in pixel
int textSize = 150; //or whatever, you have to test for the correct value, or maybe you have a function getTextSize?



void setup()
{
  /* Set up the button pins as inputs, set pull-up resistor */
  for (int i=0; i<3; i++)
  {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
 
  hours = HOURS;
  minutes = MINUTES;
  seconds = SECONDS;
  ampm = AMPM;
 
  /* Initialize the LCD, set the contrast, clear the screen */
  lcd.init(PHILLIPS);
  lcd.contrast(20);
  lcd.clear(BACKGROUND);
  testPattern();


  displayDigitalTime(hours, minutes, seconds, ampm);  // Draw the digital clock text
}

void loop()
{
  /* We'll run around checking for button presses,
     until it's been a second */
  while(millis() % 1000)
  {
    if (!digitalRead(buttonPins[2]))
      setTime();  // If S3 was pressed, go set the time
  }
 
  {
  now = millis();
  if ( now - time >= 10 ) // 10 milliseconds has passed
  {
    time = now;
    lcd.setStr("ArduinoPat", x, 20, C_COLOR, BACKGROUND);
    x--;
    if (x < -textSize) //if the text is out of the screen, reset x so the message appear again from the right
      x = 320;
  }
}
 
  /* We'll get here if it's been a second. We need to increase
  seconds by 1 and then go from there */
  seconds++;
  if (seconds >= 60)
  {
    seconds = 0;  // If seconds is 60, set it back to 0
    minutes++;    // and increase minutes by 1
    if (minutes >= 60)
    {
      minutes = 0;  // If minutes is 60, set it back to 0
      hours++;      // and increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // If it's 12 o'clock, flip ampm
      if (hours >= 13)
        hours = 1;  // If hours is 13, set it to 1. 12-hr clock.
    }
  }
  /* Once each second, we'll redraw the clock with new values */


  displayDigitalTime(hours, minutes, seconds, ampm);
}
/*
  setTime uses on-shield switches S1, S2, and S3 to set the time
  pressing S3 will exit the function. S1 increases hours, S2
  increases seconds.
 */
void setTime()
{
  /* Reset the clock to midnight */
  seconds = 0;
  minutes = 0;
  hours = 12;
  ampm = 0;
 
  /* Draw the clock, so we can see the new time */


  displayDigitalTime(hours, minutes, seconds, ampm);
   
  while (!digitalRead(buttonPins[2]))
    ;  // wait till they let go of S1
 
  /* We'll run around this loop until S3 is pressed again */
  while(digitalRead(buttonPins[2]))
  {
    /* If S1 is pressed, we'll update the hours */
    if (!digitalRead(buttonPins[0]))
    {
      hours++;  // Increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // Flip am/pm if it's 12 o'clock
      if (hours >= 13)
        hours = 1;  // Set hours to 1 if it's 13. 12-hour clock.
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
    if (!digitalRead(buttonPins[1]))
    {
      minutes++;  // Increase minutes by 1
      if (minutes >= 60)
        minutes = 0;  // If minutes is 60, set it back to 0
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
  }
  /* Once S3 is pressed, we'll exit, but not until it's released */
  while(!digitalRead(buttonPins[2]))
    ;
}

/*
  displayDigitalTime() takes in values for hours, minutes, seconds
  and am/pm. It'll print the time, in digital format, on the
  bottom of the screen.
*/
void displayDigitalTime(int h, int m, int s, int ap)
{
  char timeChar[13] = {'x', 'x', 0x0A, 'x', 'x', 0x0A, 'x', 'x', ' ', ' '};
 
  /* Gotta turn the values into individual integers */
  timeChar[0] = h/10;
  timeChar[1] = h - (timeChar[0] * 10);
  timeChar[3] = m/10;
  timeChar[4] = m - (timeChar[3] * 10);
  timeChar[6] = s/10;
  timeChar[7] = s - (timeChar[6] * 10);
 
  /* once we have each integer separated, we need to turn them
     into displayable characters. Adding 0x30 does this (check an
     ASCII table. We set the colons to 0x0A initially, this will
     turn them into the proper 0x3A.*/
  for (int i=0; i<8; i++)
    timeChar[i] += 0x30;
   
  timeChar[8] = ' ';  // add a space between the time and AM/PM
 
  /* Add AM or PM to the end of the timeChar string */
  if (!ap)
  {
    timeChar[9] = 'A';
    timeChar[10] = 'M';
  }
  else
  {
    timeChar[9] = 'P';
    timeChar[10] = 'M';
  }
 
  /* add some blank spaces after the time, otherwise it'll display
     unwanted characters */
  timeChar[11] = ' ';
  timeChar[12] = ' ';
 
  /* Print the time on the clock */
  lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 0, 20, C_COLOR, BACKGROUND);
  lcd.setStr("ArduinoPat", 2, 20, C_COLOR, BACKGROUND);
}

void testPattern()
{
 
 
  lcd.setRect(0, 2, 131, 19, 1, WHITE);
  lcd.setRect(0, 19, 131, 35, 1, YELLOW);
  lcd.setRect(0, 35, 131, 51, 1, CYAN);
  lcd.setRect(0, 51, 131, 67, 1, GREEN);
  lcd.setRect(0, 67, 131, 83, 1, MAGENTA);
  lcd.setRect(0, 83, 131, 99, 1, RED);
  lcd.setRect(0, 99, 131, 115, 1, BLUE);
  lcd.setRect(0, 115, 131, 131, 1, BLACK);
}







Thanks for reply !!!

Regards,

ArduinoPat, Patrick , The Netherlands

39  Using Arduino / Programming Questions / Sparkfun LCD Shield on: October 21, 2012, 08:52:02 am
Dear All,

I made a sketch for my LCD shield ( NOKIA ) but i will scroll my text ,
Is this possible ?
To scroll the text "ArduinoPAt" from the right to the left ?

Find attached the sketch and Movie:

Code:
#include <ColorLCDShield.h>

// Enter the time below in 12-hr format
#define HOURS 10
#define MINUTES 21
#define SECONDS 00
#define AMPM 0  // enter 0 for AM, 1 for PM

#define CLOCK_RADIUS 50  // radius of clock face
#define CLOCK_CENTER 55  // If you adjust the radius, you'll probably want to adjust this
#define H_LENGTH  30  // length of hour hand
#define M_LENGTH  40  // length of minute hand
#define S_LENGTH  48  // length of second hand

#define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
#define C_COLOR  RED  // This is the color of the clock face, and digital clock
#define H_COLOR  BLUE  // hour hand color
#define M_COLOR  GREEN  // minute hand color
#define S_COLOR  YELLOW  // second hand color

LCDShield lcd;

int hours, minutes, seconds, ampm;
int buttonPins[3] = {3, 4, 5};

void setup()
{
  /* Set up the button pins as inputs, set pull-up resistor */
  for (int i=0; i<3; i++)
  {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);
  }
 
  hours = HOURS;
  minutes = MINUTES;
  seconds = SECONDS;
  ampm = AMPM;
 
  /* Initialize the LCD, set the contrast, clear the screen */
  lcd.init(PHILLIPS);
  lcd.contrast(20);
  lcd.clear(BACKGROUND);
  testPattern();


  displayDigitalTime(hours, minutes, seconds, ampm);  // Draw the digital clock text
}

void loop()
{
  /* We'll run around checking for button presses,
     until it's been a second */
  while(millis() % 1000)
  {
    if (!digitalRead(buttonPins[2]))
      setTime();  // If S3 was pressed, go set the time
  }
 
  /* We'll get here if it's been a second. We need to increase
  seconds by 1 and then go from there */
  seconds++;
  if (seconds >= 60)
  {
    seconds = 0;  // If seconds is 60, set it back to 0
    minutes++;    // and increase minutes by 1
    if (minutes >= 60)
    {
      minutes = 0;  // If minutes is 60, set it back to 0
      hours++;      // and increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // If it's 12 o'clock, flip ampm
      if (hours >= 13)
        hours = 1;  // If hours is 13, set it to 1. 12-hr clock.
    }
  }
  /* Once each second, we'll redraw the clock with new values */


  displayDigitalTime(hours, minutes, seconds, ampm);
}
/*
  setTime uses on-shield switches S1, S2, and S3 to set the time
  pressing S3 will exit the function. S1 increases hours, S2
  increases seconds.
 */
void setTime()
{
  /* Reset the clock to midnight */
  seconds = 0;
  minutes = 0;
  hours = 12;
  ampm = 0;
 
  /* Draw the clock, so we can see the new time */


  displayDigitalTime(hours, minutes, seconds, ampm);
   
  while (!digitalRead(buttonPins[2]))
    ;  // wait till they let go of S1
 
  /* We'll run around this loop until S3 is pressed again */
  while(digitalRead(buttonPins[2]))
  {
    /* If S1 is pressed, we'll update the hours */
    if (!digitalRead(buttonPins[0]))
    {
      hours++;  // Increase hours by 1
      if (hours == 12)
        ampm ^= 1;  // Flip am/pm if it's 12 o'clock
      if (hours >= 13)
        hours = 1;  // Set hours to 1 if it's 13. 12-hour clock.
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
    if (!digitalRead(buttonPins[1]))
    {
      minutes++;  // Increase minutes by 1
      if (minutes >= 60)
        minutes = 0;  // If minutes is 60, set it back to 0
       
      /* and update the clock, so we can see it */


      displayDigitalTime(hours, minutes, seconds, ampm);
    }
  }
  /* Once S3 is pressed, we'll exit, but not until it's released */
  while(!digitalRead(buttonPins[2]))
    ;
}

/*
  displayDigitalTime() takes in values for hours, minutes, seconds
  and am/pm. It'll print the time, in digital format, on the
  bottom of the screen.
*/
void displayDigitalTime(int h, int m, int s, int ap)
{
  char timeChar[13] = {'x', 'x', 0x0A, 'x', 'x', 0x0A, 'x', 'x', ' ', ' '};
 
  /* Gotta turn the values into individual integers */
  timeChar[0] = h/10;
  timeChar[1] = h - (timeChar[0] * 10);
  timeChar[3] = m/10;
  timeChar[4] = m - (timeChar[3] * 10);
  timeChar[6] = s/10;
  timeChar[7] = s - (timeChar[6] * 10);
 
  /* once we have each integer separated, we need to turn them
     into displayable characters. Adding 0x30 does this (check an
     ASCII table. We set the colons to 0x0A initially, this will
     turn them into the proper 0x3A.*/
  for (int i=0; i<8; i++)
    timeChar[i] += 0x30;
   
  timeChar[8] = ' ';  // add a space between the time and AM/PM
 
  /* Add AM or PM to the end of the timeChar string */
  if (!ap)
  {
    timeChar[9] = 'A';
    timeChar[10] = 'M';
  }
  else
  {
    timeChar[9] = 'P';
    timeChar[10] = 'M';
  }
 
  /* add some blank spaces after the time, otherwise it'll display
     unwanted characters */
  timeChar[11] = ' ';
  timeChar[12] = ' ';
 
  /* Print the time on the clock */
  lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 0, 20, C_COLOR, BACKGROUND);
  lcd.setStr("ArduinoPat", 2, 20, C_COLOR, BACKGROUND);
}

void testPattern()
{
 
 
  lcd.setRect(0, 2, 131, 19, 1, WHITE);
  lcd.setRect(0, 19, 131, 35, 1, YELLOW);
  lcd.setRect(0, 35, 131, 51, 1, CYAN);
  lcd.setRect(0, 51, 131, 67, 1, GREEN);
  lcd.setRect(0, 67, 131, 83, 1, MAGENTA);
  lcd.setRect(0, 83, 131, 99, 1, RED);
  lcd.setRect(0, 99, 131, 115, 1, BLUE);
  lcd.setRect(0, 115, 131, 131, 1, BLACK);
}






Thsanks for read this post,

Regards,

ArduinoPat , The Netherlands

40  Using Arduino / Programming Questions / LED Matrix 5x7 first project is working , but ........ on: September 23, 2012, 04:56:08 am
Hello All,

I have test my first ledmatrix well, but is it possible to scroll this text from the right to the left ??
Maby some one can help me on the right way for making this possible.

Find attached the sketch i use now:

Code:
/*
 * matrixMpxAnimation sketch
 * PD7X
 */


// a 0 indicates the LED is off, 1 is on

byte BigP[] = {
  B11110,
  B10001,
  B10001,
  B11110,
  B10000,
  B10000,
  B10000};

byte BigD[] = {
  B11110,
  B10001,
  B10001,
  B10001,
  B10001,
  B10001,
  B11110};


byte Big7[] = {
  B11111,
  B00001,
  B00010,
  B00100,
  B00100,
  B00100,
  B00100};
 
 byte BigX[] = {
  B10001,
  B01010,
  B00100,
  B00100,
  B00100,
  B01010,
  B10001};
  
  
  
const int columnPins[] = {  6, 5, 4, 3, 2};
const int rowPins[]    = { 10,11,12,15,16,17,18};

void setup() {
  for (int i = 0; i < 8; i++)
  {
    pinMode(rowPins[i], OUTPUT);        // make all the LED pins outputs
    pinMode(columnPins[i], OUTPUT);
    digitalWrite(columnPins[i], HIGH);  // disconnect column pins from Ground
  }
}

void loop() {
  int pulseDelay =100 ;          // milliseconds to wait between beats

  show(BigP, 500);      // followed by the big Letter for 200ms
  show(BigD, 500);
  show(Big7, 500);
  show(BigX, 500);
  delay(pulseDelay);              // show nothing between beats
}

// routine to show a frame of an image stored in the array pointed to
// by the image parameter.
// the frame is repeated for the given duration in milliseconds
void show( byte * image, unsigned long duration)
{
 unsigned long start = millis();            // begin timing the animation
 while (start + duration > millis())        // loop until duration period has passed
  {
    for(int row = 0; row < 7; row++)
    {
      digitalWrite(rowPins[row], HIGH);          // connect row to +5 volts
      for(int column = 0; column < 5; column++)
      {
        boolean pixel = bitRead(image[row],column);
        if(pixel == 1)
        {
          digitalWrite(columnPins[column], LOW);  // connect column to Gnd
        }
        delayMicroseconds(300);                   // a small delay for each LED
        digitalWrite(columnPins[column], HIGH);   // disconnect column from Gnd
      }
      digitalWrite(rowPins[row], LOW);            // disconnect LEDs
    }
  }
}
      
    


Also find attached the Youtube Link,




Thank's for reading this post !!!

Regards ,

ArduinoPat,
41  Using Arduino / Programming Questions / Re: ++ SOLVED ++array label question on: August 10, 2012, 09:49:25 am
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:
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
42  Using Arduino / Programming Questions / ++SOLVED++ LCD Clear array label question on: August 10, 2012, 04:07:35 am
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 ????



Code:
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.
43  Using Arduino / Programming Questions / [ SOLVED ] array label question on: August 09, 2012, 12:51:00 pm
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  smiley



Best Regards,

Patrick , Maarssen The Netherlands
44  Using Arduino / Programming Questions / Re: array label question on: August 09, 2012, 08:44:32 am
Thanks for reply PaulS,

Wat you have send is just what i mean ;-)
I have try this sketch but it's not working yet ;-((

What do i wrong:

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

void setup()

{
    Serial.begin(9600);
    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++)
  {
    int val = digitalRead(inputPins[index]);  // read input value
    if (val == LOW)                       // check if the switch is pressed
    {
      digitalWrite(ledPins[index], HIGH); // turn LED on if switch is pressed
    }
    else
    {
      digitalWrite(ledPins[index], LOW);      // turn LED off
    }
  }
 
  byte index  = 4;
   if(digitalRead(inputPins[index]) == HIGH)
{
   digitalWrite(ledPins[index], HIGH);
   Serial.print(switchPinNames[index]);
   Serial.print(" is pressed, so the ");
   Serial.print(ledPinNames[index]);
   Serial.println(" LED was turned on");
}
 
 
 
}






When i push the first button ( switch red ) the serial Monitor shows:
green is pressed so , the led  $#$%%^ was turned on
green is pressed so , the led  $#$%%^ was turned on
green is pressed so , the led  $#$%%^ was turned on

Find attached movie:



the other buttons will light up the LED , but it will not show at the serial monitor ???

What i 'am doing wrong with this sketch ??
45  Using Arduino / Programming Questions / ++ SOLVED ++array label question on: August 09, 2012, 04:08:46 am
I was wondering if it is possible to label a array of switches ?
For example :
Switch one = LED Red
Switch Two = LED Green
Switch Three = LED Yellow

First i did an easy test with one button , find youtube example:



I was test the sketch in the COOKBOOK , Recipe 2.4 ( Groups and values )

Code:
/*
 array sketch
 an array of switches controls an array of LEDs
 see Chapter 5 for more on using switches
 see Chapter 7 for information on LEDs
 */

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

void setup()
{
  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++)
  {
    int val = digitalRead(inputPins[index]);  // read input value
    if (val == LOW)                       // check if the switch is pressed
    {
      digitalWrite(ledPins[index], HIGH); // turn LED on if switch is pressed
    }
    else
    {
      digitalWrite(ledPins[index], LOW);      // turn LED off
    }
  }
}
      
    

I understand the working of this code, but how can i  put a name at Ledpins 10,11,12,13 ??

I will show this at the LCD display ,during pushing a switch

Regards,

Patrick
Pages: 1 2 [3] 4