Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Boost Logger
- - Source Code NOT compiled for: Arduino Pro Mini 5V
- - Source Code created on: 2024-10-01 16:05:50
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Arduino boost controller low and high boost */
- /* nextion 3 inch rotary encoder eeprom for config */
- /* digital toggel for low high low and high boost */
- /* settings Boost display max boost hold and status */
- /* led for low high boost and frequency for solenoid */
- /* sd card for */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <SdFat.h> // https://github.com/greiman/SdFat
- #include <Nextion.h> // Include Nextion library for display handling
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Define constants for boost control
- const uint8_t LOW_BOOST_PIN = 2; // Digital pin for low boost toggle
- const uint8_t HIGH_BOOST_PIN = 3; // Digital pin for high boost toggle
- const uint8_t LED_LOW_PIN = 4; // LED pin for low boost indication
- const uint8_t LED_HIGH_PIN = 5; // LED pin for high boost indication
- // Define rotary encoder pins
- const uint8_t ENCODER_A_PIN = 6; // Rotary encoder pin A
- const uint8_t ENCODER_B_PIN = 7; // Rotary encoder pin B
- // Define SD card SPI pins
- const uint8_t kl_SDCardModule_SPI_PIN_CS_D10 = 10;
- // Create instances of libraries
- SdFat sd; // Create an instance of the SdFat class for SD card handling.
- File file; // Create an instance of the File class for file operations.
- Nextion myNextion(8, 9); // Create an instance of the Nextion display (TX, RX pins)
- // Variables to hold boost settings
- bool lowBoostEnabled = false;
- bool highBoostEnabled = false;
- // Function to initialize the rotary encoder
- void setupEncoder() {
- pinMode(ENCODER_A_PIN, INPUT);
- pinMode(ENCODER_B_PIN, INPUT);
- }
- // Function to read rotary encoder value
- void readEncoder() {
- // Implement rotary encoder reading logic here
- }
- // Function to update boost settings
- void updateBoostSettings() {
- if (digitalRead(LOW_BOOST_PIN) == HIGH) {
- lowBoostEnabled = !lowBoostEnabled; // Toggle low boost
- digitalWrite(LED_LOW_PIN, lowBoostEnabled ? HIGH : LOW); // Update LED status
- }
- if (digitalRead(HIGH_BOOST_PIN) == HIGH) {
- highBoostEnabled = !highBoostEnabled; // Toggle high boost
- digitalWrite(LED_HIGH_PIN, highBoostEnabled ? HIGH : LOW); // Update LED status
- }
- }
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- Serial.begin(9600); // Start serial communication at 9600 baud rate.
- // Initialize the chip select pin for the SD card.
- pinMode(kl_SDCardModule_SPI_PIN_CS_D10, OUTPUT);
- digitalWrite(kl_SDCardModule_SPI_PIN_CS_D10, HIGH); // Set CS pin high.
- // Start the SPI library.
- SPI.begin();
- // Initialize the SD card.
- if (!sd.begin(kl_SDCardModule_SPI_PIN_CS_D10)) {
- Serial.println("SD card initialization failed!");
- return; // Exit setup if SD initialization fails.
- }
- Serial.println("SD card initialized successfully.");
- // Initialize boost control pins
- pinMode(LOW_BOOST_PIN, INPUT_PULLUP);
- pinMode(HIGH_BOOST_PIN, INPUT_PULLUP);
- pinMode(LED_LOW_PIN, OUTPUT);
- pinMode(LED_HIGH_PIN, OUTPUT);
- // Initialize rotary encoder
- setupEncoder();
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Update boost settings based on toggle switches
- updateBoostSettings();
- // Example of writing to a file on the SD card.
- if (!file.open("test.txt", FILE_WRITE)) {
- Serial.println("Error opening test.txt");
- return; // Exit loop if file opening fails.
- }
- // Write a test message to the file.
- file.println("Low Boost: " + String(lowBoostEnabled) + ", High Boost: " + String(highBoostEnabled));
- file.close(); // Close the file after writing.
- // Reopen the file for reading.
- if (!file.open("test.txt", FILE_READ)) {
- Serial.println("Error opening test.txt for reading");
- return; // Exit loop if file opening fails.
- }
- // Read and print the contents of the file.
- Serial.println("Contents of test.txt:");
- while (file.available()) {
- Serial.write(file.read()); // Read and write each byte to Serial.
- }
- file.close(); // Close the file after reading.
- // Read rotary encoder value
- readEncoder();
- // Add a delay before the next loop iteration.
- delay(1000); // Delay for 1 second.
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement