6_5 Toggle Message Between Screen Rows

Bounce a Message Between Screen Rows

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port, make sure that your Code Lab Mini Screen Add-On (sold separately) is attached, and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.

If you haven't set up your Code Lab Mini Screen Add-On yet, visit Chapter 0 to watch a video showing you how to do that.


// Move a message back and forth between the top and bottom rows of the screen with a button press #include "CLMiniScreen.h" //A code library enables new functions to be used with the screen CLMiniScreen lcd; //the library name is followed by the 'name' you give the LCD screen. Here it is 'lcd' int row = 0; //An integer (whole number) variable to keep track of which row the message is on (0 or 1). void setup(){ pinMode(4,INPUT_PULLUP); //button lcd.begin(); //.begin() 'sets up' the screen } void loop(){ if(digitalRead(4)==LOW){ //if button 4 is pressed row++; //add one to a variable. Now row = its former value + 1 lcd.clear(); //clear off any message on the screen when the variable changes delay(250); //delay to release your finger from the button without counting multiple presses } if(row > 1){ //if row is greater than 1... row = 0; //Reset the variable to zero } lcd.setCursor(0,row); //set the cursor to the left position and either top or bottom row, depending on the variable lcd.print("Over Here!"); //print the message } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Coming Soon!