Hello everyone,
I'm having a flickering problem with my display, when the analogRead value I'm targeting is reached, my display is flickering, what I'm I doing wrong in my sketch ?
Here is my code, but keep in mind that I am learning it the hard way....crash & burn .
Thanks for reading me .
/*Relay CONNECTED TO PIN D4.
Start button CONNECTED TO PIN D7, PULLUP
Stop button CONNECTED TO PIN D8, PULLUP
Analog input CONNECTED TO PIN A0.
Display is a Digole Color Display, 160 x 128, 1.8 inch. I2C interface
Main supply provided by antenna tuner port (12vdc @ 1 amp. max), using an external voltage regulator, not Vin.*/
#define _Digole_Serial_I2C_ // Using Digole I2C color display, 160 x 128, 1.8 inch.
#include <Wire.h>
#include <DigoleSerial.h>
DigoleSerialDisp mydisp( &Wire, '\x27' ); // I2C on Arduino NANO: SDA on a A4, and SCL on A5.
const int relayPin = 4; // D4 on Arduino,RELAY ENABLES WITH A LOW SIGNAL
const int start_button = 7; // D7 on Arduino
const int stop_button = 8; // D8 on Arduino
const int meterPin = A0; // Input pin from meter jack, 0 to 5 volts max !
int meterValue = 0; // Variable to store the value
int status = false;
void setup()
{
pinMode( relayPin, OUTPUT ); // Relay ( ENABLED WHEN LOW TRIGGERED)
pinMode( start_button, INPUT_PULLUP ); // YELLOW START PUSH BUTTON IS PRESSED
pinMode( stop_button, INPUT_PULLUP ); // RED STOP PUSH BUTTON IS PRESSED
digitalWrite( relayPin, HIGH ); // STARTING WITH RELAY DEACTIVATED
mydisp.begin();
mydisp.backLightBrightness( 100 );
mydisp.setColor(0xc0);
mydisp.clearScreen();
mydisp.drawFrame( 0, 0, 158, 126 );
mydisp.setPrintPos ( 4, 1 );
mydisp.print( "o" );
mydisp.setPrintPos ( 4, 2 );
mydisp.print( "I" );
mydisp.setPrintPos ( 5, 2 );
mydisp.setColor(0x1b);
mydisp.print( "COM IC-7600" );
mydisp.setPrintPos ( 2, 4 );
mydisp.print( "Tuner Interface" );
mydisp.setPrintPos ( 5, 6 );
mydisp.print( "By VE2GIQ" );
mydisp.setPrintPos ( 1, 8 );
mydisp.print( "03/18 Ver. 1.0" );
delay ( 2000 );
mydisp.setColor( 0x1c );
mydisp.clearScreen();
mydisp.drawFrame( 0, 0, 158, 126 );
mydisp.setFont( 51 ); // Font size are: 6, 10, 18, 51, 120, 123, 0 is default
mydisp.setPrintPos ( 4.7, 1 );
mydisp.print("TUNER");
mydisp.setFont( 0 );
mydisp.setPrintPos ( 5.1, 4 );
mydisp.print("INTERFACE");
mydisp.setFont( 51 );
mydisp.setPrintPos ( 4.5, 3 );
mydisp.print("READY");
mydisp.setFont( 10 );
mydisp.setPrintPos ( 4, 12 );
mydisp.setColor( 0xe0 );
mydisp.print( "PUSH TO TUNE" );
mydisp.setColor( 0xfc );
mydisp.setPrintPos ( 9, 12 );
mydisp.print( "START" );
}
void loop()
{
meterValue = analogRead(meterPin); // Read the value from the sensor
float voltage = meterValue * (4.30 / 1024.0); //4.30 volts is the maximum voltage read at the meter jack.
// START TUNING WHEN YELLOW BUTTON IS PRESSED
if ( digitalRead( start_button ) == LOW) // YELLOW START BUTTON PRESSED
{
status = !status;
digitalWrite ( relayPin, LOW ); // Turn ON relay
delay(200);
mydisp.backLightBrightness( 100 );
mydisp.setColor( 0xe0 );
mydisp.clearScreen();
mydisp.drawFrame( 0, 0, 158, 126 );
mydisp.setFont( 51 );
mydisp.setPrintPos ( 4, 1 );
mydisp.print( "TUNING" );
mydisp.setPrintPos ( 2, 2 );
mydisp.print( "ANTENNA" );
mydisp.setFont( 10 );
mydisp.setColor( 0x1c );
mydisp.setPrintPos ( 8, 10 );
mydisp.print( "PLEASE WAIT" );
mydisp.setPrintPos ( 12, 11 );
mydisp.print( "OR" );
mydisp.setPrintPos ( 4, 12 );
mydisp.print( "PUSH TO ABORT" );
mydisp.setPrintPos ( 9, 12 );
mydisp.setColor( 0xe0 );
mydisp.print( "STOP" );
}
else if ( digitalRead( stop_button ) == LOW) // RED STOP BUTTON PRESSED
{
status = !status;
digitalWrite ( relayPin, HIGH ) ; // Turn OFF relay
delay(100);
mydisp.setColor( 0x1c );
mydisp.clearScreen();
mydisp.drawFrame( 0, 0, 158, 126 );
mydisp.setFont( 51 ); // Font size are: 6, 10, 18, 51, 120, 123, 0 is default
mydisp.setPrintPos ( 4.7, 1 );
mydisp.print("TUNER");
mydisp.setFont( 0 );
mydisp.setPrintPos ( 5.1, 4 );
mydisp.print("INTERFACE");
mydisp.setFont( 51 );
mydisp.setPrintPos ( 4.5, 3 );
mydisp.print("READY");
mydisp.setFont( 10 );
mydisp.setPrintPos ( 4, 12 );
mydisp.setColor( 0xe0 );
mydisp.print( "PUSH TO TUNE" );
mydisp.setColor( 0xfc );
mydisp.setPrintPos ( 9, 12 );
mydisp.print( "START" );
}
// STOP TUNING IF SWR IS LOW
if (analogRead (meterValue) < 1.00) // LOW SENSOR VALUE REACHED
{
status = !status;
digitalWrite ( relayPin, HIGH ); // Turn OFF relay
delay(200);
mydisp.setColor( 0x1c );
mydisp.clearScreen();
mydisp.drawFrame( 0, 0, 158, 126 );
mydisp.setFont( 51 ); // Font size are: 6, 10, 18, 51, 120, 123, 0 is default
mydisp.setPrintPos ( 4.7, 1 );
mydisp.print("TUNER");
mydisp.setFont( 0 );
mydisp.setPrintPos ( 5.1, 4 );
mydisp.print("INTERFACE");
mydisp.setFont( 51 );
mydisp.setPrintPos ( 4.5, 3 );
mydisp.print("READY");
mydisp.setFont( 10 );
mydisp.setPrintPos ( 4, 12 );
mydisp.setColor( 0xe0 );
mydisp.print( "PUSH TO TUNE" );
mydisp.setColor( 0xfc );
mydisp.setPrintPos ( 9, 12 );
mydisp.print( "START" );
}
else if ( digitalRead( stop_button ) == LOW) // RED STOP BUTTON PRESSED
{
status = !status;
digitalWrite ( relayPin, HIGH ) ; // Turn OFF relay
delay(200);
}
}