I’m doing an arduino program and I want it clear before becoming too big. For that, I…
- User
I’m doing an arduino program and I want it clear before becoming too big. For that, I want you divide the following code, bu putting all thee part concerning thee keyboard in a new « use_keyboard.h » and « use_keyboard.cpp », all the menus (with the part using LCD and keyoard) in a new « menu.h » and « menu.cpp »,:
#include <Keypad.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <DS3232RTC.h> #include <Streaming.h>
// Pin configuration and libraries initiation const byte ROWS = 4; const byte COLS = 4; // Définition des broches du clavier matriciel byte rowPins[ROWS] = { 33, 32, 31, 30 }; byte colPins[COLS] = { 29, 28, 27, 26 }; // Définition des touches du clavier matriciel char keys[ROWS][COLS] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' } };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); LiquidCrystal_I2C lcd(0x27, 20, 4); DS3232RTC rtc;
const int Relai_depart = 34; const int NUM_RELAYS = 8; bool relayStates[NUM_RELAYS]; int timer[NUM_RELAYS];
// Paramètre programme horaire (PH) const int Quantite_PH = 5; int Heure_PH[Quantite_PH] = {0}; int Min_PH[Quantite_PH] = {0};
// Variables int relayPins[12] = { 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 }; int buttonPin = 18; float temp1, temp2, temp3, temp4; float hum1, hum2, hum3, hum4;
void setup() { Wire.begin(); rtc.begin();
for (int i = 0; i < 12; i++) { pinMode(relayPins[i], OUTPUT); digitalWrite(relayPins[i], LOW); }
pinMode(buttonPin, INPUT_PULLUP); lcd.init(); lcd.backlight(); }
void loop() { if (digitalRead(buttonPin) == LOW) { mainMenu(); } }
void mainMenu() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("A-Relays B-Info"); lcd.setCursor(0, 1); lcd.print("D-Quit");
char key = keypad.waitForKey(); switch (key) { case 'A': relaysMenu(); break; case 'B': infoMenu(); break; case 'D': lcd.clear(); lcd.noBacklight(); break; } }
void relaysMenu() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Enter relay #");
// Collect relay number (1-12) int relay = getKeypadValue(1, 12, "Enter relay #"); relay = relay - 1 ; lcd.setCursor(0, 1); lcd.print("A:ON/OFF B:TIMER "); lcd.setCursor(0, 2); lcd.print("C:Program D:Exit ");
bool exitFlag = false; while (!exitFlag) { char key = keypad.waitForKey(); int value;
switch (key) { case 'A': relayStates[relay] = !relayStates[relay]; break;
case 'B': value = getKeypadValue(0, 999, "Enter Timer:"); if (value > -1) { relayStates[relay] = 1; timer[relay] = value; } break; case 'C': value = getKeypadValue(0, 24, "Enter Heure PH:"); if (value > -1) { Heure_PH[relay] = value; value = getKeypadValue(0, 60, "Enter Min PH:"); if (value > -1) { Min_PH[relay] = value; timer[relay] = getKeypadValue(1, 999, "Enter Duration:"); } } break; case 'D': exitFlag = true; lcd.clear(); lcd.noBacklight(); break; - Assistant
I have divided the code into specified files as requested:
main.ino:
#include <Wire.h> #include <DS3232RTC.h> #include "use_keyboard.h" #include "menu.h" DS3232RTC rtc; void setup() { Wire.begin(); initKeyboard(); initLCD(); initRTC(); initRelays(); } void loop() { checkMenuButton(); }use_keyboard.h:
#ifndef USE_KEYBOARD_H #define USE_KEYBOARD_H #include <Keypad.h> extern Keypad keypad; void initKeyboard(); int getKeypadValue(int minVal, int maxVal, char* infoText); #endif // USE_KEYBOARD_H - User
correct your answer with new files "RELAYS.h" and "RELAYS.cpp" inluuding all the relays managing
- Assistant
Here's the updated version with "RELAYS.h" and "RELAYS.cpp" files managing the relays:
main.ino:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.