Hi guys,
I'm trying to do a sort of phone with the arduino Esplora. I set that when the button to navigate is pressed, it makes a sound and add (or remove) 1 to a variable. Then, it chekcs the variable value to mark the various funcitionalities. The problem is that the buzzer keeps making sounds and only the first functionality is green. Also, I tried to initialise a Serial Monitor showing the value of "posizionemenu", but it remains 0.
Thanks in advance
Here's the code
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <Esplora.h>
#define cs 7
#define rst 1
#define dc 0
#define SD_CS 8
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
#define sclk 15
#define mosi 16
int posizionemenu = 0;
int scendi = Esplora.readButton(SWITCH_DOWN);
int sali = Esplora.readButton(SWITCH_UP);
int seleziona = Esplora.readButton(SWITCH_RIGHT);
int indietro = Esplora.readButton(SWITCH_LEFT);
boolean menu = true;
void setup() {
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
tft.setRotation(1);
tft.setCursor(0,0);
tft.setTextColor(ST7735_WHITE);
tft.print("music");
tft.setCursor(0,25);
tft.print("photos");
tft.setCursor(0,50);
tft.print("phone");
tft.setCursor(0,75);
tft.print("SMS");
Serial.begin(9600);
}
void loop() {
if(scendi == LOW){
posizionemenu++;
Esplora.tone(1000);
delay(100);
Esplora.noTone();
}
if(sali==LOW){
posizionemenu--;
Esplora.tone(1000);
delay(100);
Esplora.noTone();
}
Serial.print(posizionemenu);
delay(1000);
if(posizionemenu==0){
tft.setCursor(0,0);
tft.setTextColor(ST7735_GREEN);
tft.print("music");
}
else{
tft.setCursor(0,0);
tft.setTextColor(ST7735_WHITE);
tft.print("music");
}
if(posizionemenu==1){
tft.setCursor(0,25);
tft.setTextColor(ST7735_GREEN);
tft.print("photos");
}
else{
tft.setCursor(0,25);
tft.setTextColor(ST7735_WHITE);
tft.print("photos");
}
if(posizionemenu==2){
tft.setCursor(0,50);
tft.setTextColor(ST7735_GREEN);
tft.print("phone");
}
else{
tft.setCursor(0,50);
tft.setTextColor(ST7735_WHITE);
tft.print("phone");
}
if (posizionemenu==3){
tft.setCursor(0,75);
tft.setTextColor(ST7735_GREEN);
tft.print("SMS");
}
else{
tft.setCursor(0,75);
tft.setTextColor(ST7735_WHITE);
tft.print("SMS");
}
if (posizionemenu==4){
posizionemenu=3;
}
if (posizionemenu<0){
posizionemenu=0;
}
}