HI, im working on a Prop Scifi laser gun, im using an arduino nano r4, dfminiplayer, and waveshare 1.69" lcd screen.
I was using the waveshare supplied driver but switched to Adafruit gfx library because it was like 500ms faster to refresh the counter on the display.
Anyway right now I'm stumped that my counter stops decreasing after it gets to 14, even if I keep pushing the button.
I can use the button with the arduino button count tutorial and it works as expected.here
thanks for reading and I appreciate your help.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Define the pin connections
#define TFT_CS 10
#define TFT_RST 8 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 7
const int buttonPin1 = 2; // the number of the pushbutton pins
const int buttonPin2 = 3; //RELOAD SWITCH
const int ledPin = 6; // the number of the LED pin
static const uint8_t PIN_MP3_TX = 4; // Connects to DFMINI module's RX
static const uint8_t PIN_MP3_RX = 5; // Connects to DFMINI module's TX
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
//** define colors
#define black 0x0000
#define BLACK 0x0000
#define WHITE 0xffff
#define GREY 0x8410
#define GREY 0x8C71
#define DGREY 0x8C71
#define BLUE 0x181F
#define PINK 0xFB9F
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Create the Player object
DFRobotDFPlayerMini player;
int buttonState1 = 0, buttonState2 = 1; // variable for reading the pushbuttons status
int preState1 = 0, preState2 = 1;
int counter = 16;
void setup() {
// initialize the LED pin as an output
//LED flashes during decrement of counter
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
Serial.begin(9600);
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) {
// Set volume to maximum (0 to 30).
player.volume(30);
}
else {
Serial.println("Connecting to DFPlayer Mini failed!" );
}
Serial.begin(9600);
tft.init(240, 280); // Init ST7789 280x240
Serial.println(F("Initialized"));
Serial.println("16");
tft.fillScreen(GREY);
tft.setRotation(1); //screen horizontal
}
void loop() {
// read the state of the pushbutton
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (counter > 0) {
if (buttonState1 == HIGH && preState1 == LOW ){
counter--;
player.playMp3Folder(2);
digitalWrite(ledPin, HIGH);
delay(300); digitalWrite(ledPin, LOW);
Serial.println(counter); preState1 = 1;
}
else (buttonState1 == 0);{
preState1 = 0;
}
}
}