Hi everyone, I'm a total beginner and am looking for some help (so go easy on me). I have an Arduino Mega with a LCD screen from Adafruit. I'm attempting to design a testing unit to be able to read pulses from an encoder and hopefully eventually be able to do a count test, whereby counting only the A &B pulses on one rotation (from Z pulse to Z pulse).
So far, I have it working where it'll show the number of counts that have been sensed on screen. The LCD screen also has buttons; I'm hoping to be able to paginate information. Not sure exactly how to do that. I've been looking at the Adafruit "Hello,World" example and have been able to figure out how to paginate, but can't get it to update continuously. I've since reverted to my working project where everything working and is just on one screen. This is what I have thus far:
// Include the library code:
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <PinChangeInterrupt.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// Encoder output to Arduino Interrupt pin. Tracks the pulse count.
#define ENC_A 18
#define ENC_B 19
// Keep track of the number of pulses
volatile long pulse_count_a = 0;
volatile long pulse_count_b = 0;
volatile long pulse_count_z = 0;
void setup() {
// Put your setup code here, to run once:
// Open the serial port at 9600 bps
Serial.begin(9600);
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Print to the LCD.
lcd.setCursor(0, 0);
lcd.print("A:");
lcd.setCursor(0, 1);
lcd.print("B:");
lcd.setCursor(11, 0);
lcd.print("Z:");
// Set pin states of the encoder
pinMode(ENC_A , INPUT_PULLUP);
pinMode(ENC_B , INPUT_PULLUP);
// Every time the pin goes high, this is a pulse
attachInterrupt(digitalPinToInterrupt(ENC_A), pulse_a, RISING);
attachInterrupt(digitalPinToInterrupt(ENC_B), pulse_b, RISING);
attachPinChangeInterrupt(23, pulse_z, RISING);
}
uint8_t i=0;
void loop() {
// Put your main code here, to run repeatedly:
// Write pulse counts to display
lcd.setCursor(2,0);
lcd.print(pulse_count_a);
lcd.setCursor(2,1);
lcd.print(pulse_count_b);
lcd.setCursor(13,0);
lcd.print(pulse_count_z);
}
// Increment the number of A pulses by 1
void pulse_a() {
pulse_count_a++;
}
// Increment the number of B pulses by 1
void pulse_b() {
pulse_count_b++;
}
// Increment the number of Z pulses by 1
void pulse_z() {
pulse_count_z++;
}
I know that the printing section in setup() is obviously going to have to move and that code will be need to be added to sense the buttons. I actually did that at one point, however I was unable to make it continuously update as it does now (would update when I hit the update button a second time). How can I accomplish this where, for example, pressing up would display what I have thus far, but pressing down clears the screen completely and would allow me to add a whole screen with different functionality? Any help would be greatly appreciated!



