yep all typos#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define INTERVAL 1000; // removing the '=' should take care of the last few errors
#define SIRENCYCLE 2000;
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;
const int buzzer = A14;
const int PIR = A13;
const int led = A15;
int aux = 98; // this should not be 'const' and in fact also not 'bool' but 'int' or 'uint8_t' or something
MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
Adafruit_GFX_Button on_btn, off_btn;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
void setup() {
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println("Calibrate for your Touch Panel");
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(0); //PORTRAIT
tft.fillScreen(BLACK);
on_btn.initButton(&tft, 80, 330, 130, 40, WHITE, CYAN, BLACK, "ARMAR", 2);
off_btn.initButton(&tft, 240, 330, 130, 40, WHITE, CYAN, BLACK, "DESARM.", 2);
on_btn.drawButton(false);
off_btn.drawButton(false);
pinMode(PIR, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
}
void loop() {
bool down = Touch_getXY();
int leitura = digitalRead(PIR);
on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
if (on_btn.justReleased()) on_btn.drawButton();
if (off_btn.justReleased()) off_btn.drawButton();
if (on_btn.justPressed()) {
on_btn.drawButton(true);
tft.fillRect(60, 100, 180, 100, GREEN);
delay (100);
tft.fillRect(60, 100, 180, 100, BLACK);
aux = 98;
}
if (off_btn.justPressed()) {
off_btn.drawButton(true);
tft.fillRect(60, 100, 180, 100, RED);
delay (100);
tft.fillRect(60, 100, 180, 100, BLACK);
aux = 99;
StopAlarm();
}
if ((aux == 98) && (leitura == HIGH)) aux = 97;
if (aux == 97) AlarmRinging();
}
void StopAlarm() {
noTone (buzzer);
digitalWrite(led, LOW);
}
void AlarmRinging() {
static int ledState = LOW; // these variables are static & local now
static uint32_t previousMillis = millis(); // which means they hold their value and are not destroyed
// when the function ends (but not accessable outside the function)
uint32_t currentMillis = millis(); // ths section is from Blink without delay example
// the 'g' should not have been there
if (currentMillis - previousMillis >= INTERVAL) {
previousMillis = currentMillis;
if (ledState == LOW) ledState = HIGH;
else ledState = LOW;
digitalWrite(led, ledState);
}
uint16_t inCycle = currentMillis % SIRENCYCLE; // this is how i would use millis() & modulo
if (inCycle > SIRENCYCLE / 2) { // iow if it is on the way back
inCycle = SIRENCYCLE - inCycle;
}
uint16_t freq = map (inCycle, 0, SIRENCYCLE / 2, 1500, 1800 ); // use the map function to
tone(buzzer, freq);
}
bool Touch_getXY() {
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}
removed the errors for you, though some you should have been able to find as well.
note : i changed 'unsigned long' to uint32_t which in fact is a different way of writing the same thing (but shorter), an unsigned 32 bit integer.