My code works as shown, but I want to be able to have my println, flash when button State1 is low and go away when the pin is not low. (flash on for one sec and off for one sec)
I was able to get it to work using delay, but then my other inputs and println's were of course also delayed.
I also tried using mills, but my test would only flash very quickly and then go away.
Here is the basic set up... so far.
Thanks for any help!
PS the PWM is there so i can dim my lcd.
heres what it looks like when it flashes really quickly.
I was able to get it to work using delay, but then my other inputs and println's were of course also delayed.
I also tried using mills, but my test would only flash very quickly and then go away.
Here is the basic set up... so far.
Thanks for any help!
PS the PWM is there so i can dim my lcd.
Code:
#include "SPI.h"
#include "ILI9341_t3.h"
#include <font_ArialBold.h>
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST);
const int pwm = A6 ; //naming pin ‘pwm’ variable out
const int adc = A5 ; //naming pin analog input side as ‘adc’
int buttonPin1= 14; //sets pins buttons are connected to
int buttonPin2= 15;
int buttonPin3= 16;
int buttonPin4= 17;
int buttonPin5= 7;
int buttonPin6= 6;
int buttonPin7= 5;
int buttonPin8= 4;
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
pinMode(pwm,OUTPUT) ; //setting pin as output
pinMode(buttonPin1, INPUT); //assigns button pins as inputs //currently pulled high
pinMode(buttonPin2, INPUT); //currently pulled low
pinMode(buttonPin3, INPUT); //currently pulled low
pinMode(buttonPin4, INPUT); //currently pulled low
pinMode(buttonPin5, INPUT); //currently pulled high
pinMode(buttonPin6, INPUT); //currently pulled high
pinMode(buttonPin7, INPUT); //currently pulled high
pinMode(buttonPin8, INPUT); //currently pulled high
}
void loop(void) {
int adc = analogRead(A5) ; //reading analog voltage and storing it in an integer
adc = map(adc, 0, 1023, 10, 250);
analogWrite(pwm,adc) ;
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
int buttonState4 = digitalRead(buttonPin4);
int buttonState5 = digitalRead(buttonPin5);
int buttonState6 = digitalRead(buttonPin6);
if(buttonState1== LOW)
{
tft.setCursor(0, 12);
tft.setFont(Arial_24_Bold);
tft.setTextColor(ILI9341_RED);
tft.println("HELLO");
}
else
{
tft.setCursor(0, 12);
tft.setFont(Arial_24_Bold);
tft.setTextColor(ILI9341_BLACK);
tft.println("HELLO");
}
heres what it looks like when it flashes really quickly.
Code:
#include "SPI.h"
#include "ILI9341_t3.h"
#include <font_ArialBold.h>
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST);
const int pwm = A6 ; //naming pin ‘pwm’ variable out
const int adc = A5 ; //naming pin analog input side as ‘adc’
unsigned long interval=1000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
bool buttonState = false; // state variable
int buttonPin1= 14; //sets pins buttons are connected to
int buttonPin2= 15;
int buttonPin3= 16;
int buttonPin4= 17;
int buttonPin5= 7;
int buttonPin6= 6;
int buttonPin7= 5;
int buttonPin8= 4;
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
pinMode(pwm,OUTPUT) ; //setting pin as output
pinMode(buttonPin1, INPUT); //assigns button pins as inputs //currently pulled high
pinMode(buttonPin2, INPUT); //currently pulled low
pinMode(buttonPin3, INPUT); //currently pulled low
pinMode(buttonPin4, INPUT); //currently pulled low
pinMode(buttonPin5, INPUT); //currently pulled high
pinMode(buttonPin6, INPUT); //currently pulled high
pinMode(buttonPin7, INPUT); //currently pulled high
pinMode(buttonPin8, INPUT); //currently pulled high
}
void loop(void) {
int adc = analogRead(A5) ; //reading analog voltage and storing it in an integer
adc = map(adc, 0, 1023, 10, 250);
analogWrite(pwm,adc) ;
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
int buttonState4 = digitalRead(buttonPin4);
int buttonState5 = digitalRead(buttonPin5);
int buttonState6 = digitalRead(buttonPin6);
unsigned long currentMillis = millis(); // grab current time
if ((buttonState1== LOW) && (unsigned long)(currentMillis - previousMillis) >= interval)
{
tft.setCursor(0, 12);
tft.setFont(Arial_24_Bold);
tft.setTextColor(ILI9341_RED);
tft.println("HELLO");
buttonState1 = !buttonState1; // "toggles" the state
previousMillis = millis();
}
else
{
tft.setCursor(0, 12);
tft.setFont(Arial_24_Bold);
tft.setTextColor(ILI9341_BLACK);
tft.println("HELLO");
}