this is the code that fails to upload:
#include <ArduinoBLE.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_Thermal.h"
#include "1.1.h"
#include "1.2.h" // Assicurati di avere l'immagine bitmap "cuori.h" inclusa nel tuo progetto
#include "1.3.h"
#include "2.1.h"
#include "2.2.h"
#include "2.3.h"
#include "3.1.h"
#include "3.2.h"
#include "3.3.h"
//tempo utilizzo
int counter = 0; //counter che se arriva poi ai 10 sec determina la fine
unsigned long startTime = 0; //tempo effettivo di utilizzo
// SCHERMINO
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST -1
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
//COLORI SCHERMINO
#define TFT_BIANCO 0xFFFF
#define TFT_ROSA 0xFE59
#define TFT_ROSSO 0xD0A4
Adafruit_Thermal printer(&Serial1);
void setup() {
pinMode(7, OUTPUT); digitalWrite(7, LOW);
Serial.begin(19200);
printer.begin();
while (!Serial); // L'istruzione while (!Serial) attende finché la comunicazione seriale non è stabilita.
BLE.begin();
Serial.println("BLE Central - FSR control");
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
// SCHERMINO
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BIANCO);
// scritta iniziale
// tft.setFont(&Chiswick_Grotesque_Semibold7pt7b);
// drawAnimatedText("Hey sweety", 10, 70, 3);
// delay(3000);
// tft.fillScreen(TFT_BIANCO);
}
void loop() {
BLEDevice peripheral = BLE.available();
if (peripheral) {
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
if (peripheral.localName().indexOf("FSR Sensor") < 0) {
Serial.println("No 'FSR Sensor' in name");
return;
}
BLE.stopScan();
controlLed(peripheral);
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
}
void controlLed(BLEDevice peripheral) {
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
BLECharacteristic FSRCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");
if (!FSRCharacteristic) {
Serial.println("Peripheral does not have FSR characteristic!");
peripheral.disconnect();
return;
}
BLECharacteristic LightCharacteristic = peripheral.characteristic("19B10002-E8F2-537E-4F6C-D104768A1214");
if (!LightCharacteristic) {
Serial.println("Peripheral does not have Light characteristic!");
peripheral.disconnect();
return;
}
while (peripheral.connected()) {
byte value = FSRCharacteristic.read();
if (FSRCharacteristic.canRead()) {
FSRCharacteristic.readValue(value);
Serial.println(value);
// Logica per determinare l'output in base al valore più alto tra i due sensori
//SLOT 0
if (value < 30) {
int randomPhrase = random(3);
switch (randomPhrase) {
case 0:
tft.fillScreen(TFT_BIANCO);
tft.drawRGBBitmap(0, 0, (uint16_t *)unounoBitmap, UNOUNO_WIDTH, UNOUNO_HEIGHT);
delay(1000);
break;
case 1:
tft.fillScreen(TFT_BIANCO);
tft.drawRGBBitmap(0, 0, (uint16_t *)unodueBitmap, UNODUE_WIDTH, UNODUE_HEIGHT);
delay(1000);
break;
case 2:
tft.fillScreen(TFT_BIANCO);
tft.drawRGBBitmap(0, 0, (uint16_t *)unotreBitmap, UNOTRE_WIDTH, UNOTRE_HEIGHT);
delay(1000);
break;
}
//SLOT 1
} else if (value < 70) {
int randomPhrase = random(3);
switch (randomPhrase) {
case 0:
tft.fillScreen(TFT_ROSA);
tft.drawRGBBitmap(0, 0, (uint16_t *)dueunoBitmap, DUEUNO_WIDTH, DUEUNO_HEIGHT);
delay(1000);
break;
case 1:
tft.fillScreen(TFT_ROSA);
tft.drawRGBBitmap(0, 0, (uint16_t *)duedueBitmap, DUEDUE_WIDTH, DUEDUE_HEIGHT);
delay(1000);
break;
case 2:
tft.fillScreen(TFT_ROSA);
tft.drawRGBBitmap(0, 0, (uint16_t *)duetreBitmap, DUETRE_WIDTH, DUETRE_HEIGHT);
delay(1000);
break;
}
//SLOT 2
} else if (value < 200) {
int randomPhrase = random(3);
switch (randomPhrase) {
case 0:
tft.fillScreen(TFT_ROSSO);
tft.drawRGBBitmap(0, 0, (uint16_t *)treunoBitmap, TREUNO_WIDTH, TREUNO_HEIGHT);
delay(1000);
break;
case 1:
tft.fillScreen(TFT_ROSSO);
tft.drawRGBBitmap(0, 0, (uint16_t *)tredueBitmap, TREDUE_WIDTH, TREDUE_HEIGHT);
delay(1000);
break;
case 2:
tft.fillScreen(TFT_ROSSO);
tft.drawRGBBitmap(0, 0, (uint16_t *)tretreBitmap, TRETRE_WIDTH, TRETRE_HEIGHT);
delay(1000);
break;
}
}
//photoresistor e FINE
byte luce = LightCharacteristic.read();
if (LightCharacteristic.canRead()) {
LightCharacteristic.readValue(luce);
Serial.println(luce);
}
if (value < 5 && luce < 80) { //se non rileva più pressione e la luce è bassa
if (counter == 0) {
startTime = millis();
}
counter++;
} else {
counter = 0;
}
if (counter >= 10) {
if (startTime <= 15000) {
printer.setFont('A');
printer.setSize('S');
printer.justify('R');
Serial.println("hai sgravato");
} else if (startTime > 15000 && startTime <= 40000) {
printer.setFont('A');
printer.setSize('S');
printer.justify('R');
Serial.println("ciao");
} else {
printer.setFont('A');
printer.setSize('S');
printer.justify('R');
Serial.println("hello");
}
printer.sleep(); // Tell printer to sleep
delay(3000L); // Sleep for 3 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault();
while (true) {
// Loop infinito per mantenere lo stato di uscita
}
//photoresistor e FINE
}
}
Serial.println("Peripheral disconnected");
}
}
this is the code of the other Arduino, which uploads correctly:
int fsrPin = 0;
int fsrPin2 = 1;
int light;
BLEService FSRService("19B10000-E8F2-537E-4F6C-D104768A1214");
BLEByteCharacteristic FSRCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
BLEByteCharacteristic LightCharacteristic("19B10002-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
void setup() {
Serial.begin(9600);
pinMode(fsrPin, INPUT);
pinMode(fsrPin2, INPUT);
if (!BLE.begin()) {
Serial.println("Starting Bluetooth®️ Low Energy failed!");
while (1);
}
BLE.setLocalName("FSR Sensor");
BLE.setAdvertisedService(FSRService);
FSRService.addCharacteristic(FSRCharacteristic); // Aggiungi la nuova caratteristica per il sensore di forza
FSRService.addCharacteristic(LightCharacteristic); // Aggiungi la nuova caratteristica per la luce
BLE.addService(FSRService);
BLE.advertise();
Serial.println("BLE FSR Sensor Peripheral, waiting for connections...");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connesso al nano centrale: ");
Serial.println(central.address());
while (central.connected()) {
int sensorState = analogRead(fsrPin);
Serial.print("Force sensor 1 reading = ");
Serial.print(sensorState);
int sensorState2 = analogRead(fsrPin2);
Serial.print(", Force sensor 2 reading = ");
Serial.print(sensorState2);
int maxReading = max(sensorState, sensorState2);
Serial.print(", Maxreading = ");
Serial.println(maxReading);
light = analogRead(A2);
if (light > 100) {
digitalWrite(13, HIGH); //accendi e sepgni il led integrato nell'arduino
} else {
digitalWrite(13, LOW);
}
Serial.println("Light reading = " + String(light));
delay(500);
FSRCharacteristic.writeValue(maxReading);
LightCharacteristic.writeValue(light); // Aggiungi il valore di light alla caratteristica BLE
}
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}