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.
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 } } }
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
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 ???
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
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
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
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
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 ????
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
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 !!!