// STM32 Blue Pill SPI LCD Example
// Simulation: https://wokwi.com/projects/374780854731040769
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC PB7
#define TFT_CS PB6
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define BOUTON_Pin PA15
// Authorized RFID IDs
const int authorized_ids[] = {460208478, 2435355610, 987654321};
void setup() {
Serial.begin(115200);
Serial.println("Wokwi Blue Pill SPI Demo Starting...");
tft.begin();
// Clear the screen
tft.fillScreen(ILI9341_BLACK);
// Display static text
tft.setCursor(36, 120);
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(3);
tft.println("Blue Pill");
tft.setCursor(60, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.println("STM32");
}
void loop() {
static bool buttonPressed = false;
static unsigned long lastDebounceTime = 0;
static unsigned long debounceDelay = 50; // Adjust as needed
// Read the state of the button
bool buttonState = digitalRead(BOUTON_Pin);
// Check if the button state has changed
if (buttonState != buttonPressed) {
lastDebounceTime = millis(); // Reset the debounce timer
}
// Check if the button has been in the same state for longer than the debounce delay
if ((millis() - lastDebounceTime) > debounceDelay) {
// If the button state has stabilized, perform the action
if (buttonState == LOW) {
// Display RFID information
int id_choisi = choisir_id_aleatoire();
bool autorise = verifier_autorisation(id_choisi);
tft.fillScreen(ILI9341_BLACK); // Clear the screen
tft.setCursor(20, 60);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("RFID ID: ");
tft.println(id_choisi);
tft.setCursor(20, 100);
if (autorise) {
tft.setTextColor(ILI9341_GREEN);
tft.println("Authorized");
} else {
tft.setTextColor(ILI9341_RED);
tft.println("Not Authorized");
}
// Wait for a short time to prevent rapid button presses
delay(1000);
}
}
// Update the button state
buttonPressed = buttonState;
}
// Fonction pour choisir un RFID aléatoire
int choisir_id_aleatoire() {
const int list_ids[] = {123456789, 987654321, 135792468, 246813579, 460208478, 2435355610, 2235355610, 221314350};
return list_ids[random(0, sizeof(list_ids) / sizeof(list_ids[0]))];
}
// Fonction pour vérifier si le RFID est autorisé
bool verifier_autorisation(int id_choisi) {
for (int i = 0; i < sizeof(authorized_ids) / sizeof(authorized_ids[0]); i++) {
if (id_choisi == authorized_ids[i]) {
return true;
}
}
return false;
}
Loading
stm32-bluepill
stm32-bluepill