Go Down

Topic: Update HT1632 Text String on Button Press (Read 425 times) previous topic - next topic

jonjones

Hi,

I've got some text scrolling across my display but on a button press I want a couple of things to happen. I want to to change the text to something else then after about 2 seconds change back to the original string.

In theory this is quite easy using the delay() function but due to this LED display updating in the loop it just causes the display to freeze for 2 seconds when the button is pressed and then switching back to the original string.

Anybody have any ideas? Please let me know if i'm not being clear enough.

Code: [Select]
#include <font_5x4.h>
#include <HT1632.h>
#include <images.h>

int i = 0;
int wd;
char* thetext = {"Press the button"};
const int buttonPin = 2;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup () {
  // Setup and begin the matrix
  // HT1632.begin(CS1,WR,DATA)
  HT1632.begin( 9, 10, 11);


 
  // Give the width, in columns, of the assigned string
  // FONT_5x4_WIDTH and FONT_5x4_HEIGHT are parameter specified in the "font_5x4.h" file
  wd = HT1632.getTextWidth("Press the button", FONT_5X4_WIDTH, FONT_5X4_HEIGHT);


    // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

 
}

void loop () {
 
buttonState = digitalRead(buttonPin);
 
if (buttonState == HIGH) {   
thetext = "Pressed";
delay(2000);
thetext = "Press the button";

  }

  HT1632.drawTarget(BUFFER_BOARD(1));
  HT1632.clear();
  HT1632.drawText(thetext, 2*OUT_SIZE - i, 2, FONT_5X4, FONT_5X4_WIDTH, FONT_5X4_HEIGHT, FONT_5X4_STEP_GLYPH);
  HT1632.render();
 
  i = (i+1)%(wd + OUT_SIZE * 2); 
  delay(20);
}


Thanks

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy