Loading...
  Show Posts
Pages: 1 2 [3]
31  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,
32  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
33  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.
34  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
35  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 ??
36  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
37  Using Arduino / Programming Questions / Re: More buttons , to show text at lcd or serialprint on: April 22, 2012, 01:14:51 pm
Dear PaulS,

It's working , i have make a simple test with 3 Buttons, during pushing one button it will shows at the display
BUTTON-1=PRESSED
BUTTON-2=PRESSED
BUTTON-3=PRESSED

find attached my sketch,

/*
 *  Alternating switch
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);


int switchPin = 2;              // switch is connected to pin 2
int switchPin1 = 4;              // switch is connected to pin 4
int switchPin2 = 7;              // switch is connected to pin 7
int prevState;                     // variable for reading the pin status
int currState;                // variable to hold the last button state


void setup() {
 
  lcd.init();
  lcd.backlight();
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
 
  pinMode(switchPin, INPUT);     // Set the switch pin as input
  pinMode(switchPin1, INPUT);    // Set the switch pin as input
  pinMode(switchPin2, INPUT);    // Set the switch pin as input

}
  void loop(){
  currState = digitalRead(switchPin);
 
  if(currState !=prevState){
 
  if(currState == LOW){
  lcd.println("   ");
  lcd.clear();
 
  }
   
   
  else {
   
  prevState = currState;
  currState = digitalRead(switchPin);
  if(currState !=prevState)
  lcd.print(0, 0);
  lcd.print("BUTTON-1=PRESSED    ");
 
  }
  }
  prevState = currState;

 currState = digitalRead(switchPin1);
 
  if(currState !=prevState){
  if(currState == LOW){
  lcd.println("   ");
  lcd.clear();
  }
  else {
   
  prevState = currState;
  currState = digitalRead(switchPin1);
  if(currState !=prevState)
  lcd.print(0, 0);
  lcd.print("BUTTON-2=PRESSED    ");
 
  }
  }
  prevState = currState;
 
 
  currState = digitalRead(switchPin2);
 
  if(currState !=prevState){
  if(currState == LOW){
  lcd.println("   ");
  lcd.clear();
  }
  else {
   
  prevState = currState;
  currState = digitalRead(switchPin2);
  if(currState !=prevState)
  lcd.print(0, 0);
  lcd.print("BUTTON-3=PRESSED    ");
 
  }
  }
  prevState = currState;
  }


Find the example at youtube , smiley-money


Many thank's for your explain,

Best regards ,

Patrick , The Netherlands




38  Using Arduino / Programming Questions / Re: More buttons , to show text at lcd or serialprint on: April 22, 2012, 10:04:42 am
Hello PaulS,


I will use more buttons to switch over , and shows at the lcd screen at wath kind of  input the switch is ,

can you give me a complete example please ?


Thank's for reading this ,


Patrick
39  Using Arduino / Programming Questions / Re: More buttons , to show text at lcd or serialprint on: April 22, 2012, 09:47:41 am
Thank's for reply PaulS,

But it will not work yet  smiley-mad

With one button it works !!

But when i make this sketch for two buttons it will not work anymore,

look at this sketch :

/*
 *  Alternating switch
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);


int switchPin = 2;                  // switch is connected to pin 2
int switchPin2 = 4;                 // switch is connected to pin 4
int prevState;                      // variable for reading the pin status
int prevState2;                     // variable for reading the pin status
int currState;                      // variable to hold the last button state
int currState2;                     // variable to hold the last button state

void setup() {
 
  lcd.init();
  lcd.backlight();
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
 
  pinMode(switchPin, INPUT);     // Set the switch pin as input
  pinMode(switchPin2, INPUT);    // Set the switch pin as input

}
  void loop(){
  currState = digitalRead(switchPin);
 
  if(currState !=prevState){
  if(currState == LOW){
  lcd.println("   ");
  lcd.clear();
 
  currState2 = digitalRead(switchPin2);
 
  if(currState2 !=prevState2){
  if(currState2 == LOW){
  lcd.println("   ");
  lcd.clear();
 
 
 
 
  }
  else {
 
  prevState = currState;
  prevState2 = currState2;
 
  currState = digitalRead(switchPin);
  if(currState !=prevState)
  lcd.print(0, 0);
  lcd.print("BUTTON-1=PRESSED    ");
 
  currState2 = digitalRead(switchPin2);
  if(currState2 !=prevState2)
  lcd.print(0, 0);
  lcd.print("BUTTON-2=PRESSED    ");
 
 
  }
  }
  prevState = currState;
  prevState2 = currState2;

}



This will not work , but with one button it works , when i push the button the LCD shows BUTTON-1= PRESSED
When i loss the button the lcd screen is empty , and that is what i will, but then with more buttons ????


This is working :

/*
 *  Alternating switch
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);


int switchPin = 2;              // switch is connected to pin 2
int prevState;                     // variable for reading the pin status
int currState;                // variable to hold the last button state

void setup() {
 
  lcd.init();
  lcd.backlight();
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
 
  pinMode(switchPin, INPUT);    // Set the switch pin as input

}
  void loop(){
  currState = digitalRead(switchPin);
 
  if(currState !=prevState){
  if(currState == LOW){
  lcd.println("   ");
  lcd.clear();
  }
  else {
   
  prevState = currState;
  currState = digitalRead(switchPin);
  if(currState !=prevState)
  lcd.print(0, 0);
  lcd.print("BUTTON-1=PRESSED    ");
 
  }
  }
  prevState = currState;


}

Maby you can give me some information what i have to do ?

Thank's for read this !!


Patrick, The Netherlands.
40  Using Arduino / Programming Questions / +++ SOLVED +++ More buttons , to show text at lcd or serialprint on: April 21, 2012, 03:03:13 pm
Hello all,

I 'am new with the arduino , but the examples in the getting started book is not the problem for me for first of this begin with the arduino,
Now i will do an experiment with more buttons and text ( display at serial or LCD )  , with one button it will works ;-)
But now i will make a sketch with more buttons,
So when i Push button one , the screen display as example button 1 is pressed
And when i push button two , the screen displays as example button 2 is pressed , and further and further,

Now i have make a simple sketch as example with one button (Door contact ) , but i like to make this sketch with more buttons:


***************************************************************************************************************************************

/*
 *  Door alarm switch test
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);


int switchPin = 2;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int buttonState;                // variable to hold the last button state

void setup() {
 
  lcd.init();
  lcd.backlight();
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
 
  pinMode(switchPin, INPUT);    // Set the switch pin as input
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  Serial.begin(9600);           // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin);   // read the initial state
}


void loop(){
      val = digitalRead(switchPin);      // read input value and store it in val

      if (val != buttonState) {          // the button state has changed!
      if (val == LOW) {         // check if the button is NOT pressed
      lcd.clear();
      Serial.println("Door contact 1 Restored "); // put at serial
      lcd.println("  Door contact 1  "); // put text at row 1 lcd
      lcd.setCursor(0, 1); // use row  2
      lcd.print("    Restored  ");// row 2 at lcd
   
     
     
    } else {                         // the button is pressed...
      lcd.clear();
      Serial.println("Door contact 1 Activated ");// at serial
      lcd.println(" Move Detection  ");// row 1 at lcd
      lcd.setCursor(0, 1);//row  2
      lcd.print("** Activated **");//row 2 at lcd
   
     

    }
  }
 
  buttonState = val;                 // save the new state in our variable
}



This sketch is working correct , for now ,
I hope someone can help me further !!!

 smiley-mr-green
Pages: 1 2 [3]