i use deepseek not chatgpt
I know, but posts 7 and 10 refer to ChatGPT. Post 10 offered several suggestions why your DeepSeek code failed to compile.
And now your answers to my last post?
I tried the code in chatgpt but it gives a different approach, the code just gets more messed up
this is my code now I am using is arduino uno, 3 buttons for relays, 3 relays, i2c 20x4, coinslot, our project is called 3 in 1 carwash using three motors, for water, shampoo/soap and Blower and buzzer
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD setup
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Pin assignments
const int coinSlotPin = 2; // Pin for the coin slot sensor
const int waterButton = 3;
const int soapButton = 4;
const int blowerButton = 5;
const int relayWater = 6;
const int relaySoap = 7;
const int relayBlower = 8;
const int buzzer = 9; // Buzzer pin
// Default times
const int DEFAULT_WATER_TIME = 60;
const int DEFAULT_SOAP_TIME = 45;
const int DEFAULT_BLOWER_TIME = 75;
// Pause limit
const int MAX_PAUSE_COUNT = 3;
// Timing constants
const unsigned long BLINK_INTERVAL = 500; // Blink interval in milliseconds
const unsigned long BUZZER_CHECK_INTERVAL = 50; // Buzzer check interval in milliseconds
const unsigned long COIN_DEBOUNCE_TIME = 300; // Coin slot debounce time in milliseconds
const unsigned long BUTTON_DEBOUNCE_TIME = 200; // Button debounce time in milliseconds
// System state
int balance = 0;
int waterTime = 0, soapTime = 0, blowerTime = 0;
bool waterActive = false, soapActive = false, blowerActive = false;
bool waterPaused = false, soapPaused = false, blowerPaused = false;
int waterPauseCount = 0, soapPauseCount = 0, blowerPauseCount = 0;
unsigned long lastUpdateTime = 0, lastButtonBlinkTime = 0;
unsigned long lastBuzzerTime = 0, lastInsertCoinBlinkTime = 0; // Separate variable for --Insert Coin!-- blinking
bool showInsertCoin = true, showPressButton = true;
bool screenInitialized = false;
// Separate blinking states for paused timers
bool waterBlinkState = false, soapBlinkState = false, blowerBlinkState = false;
unsigned long waterLastBlinkTime = 0, soapLastBlinkTime = 0, blowerLastBlinkTime = 0;
// Coin counting variables
volatile int coinsInserted = 0; // Volatile because it's modified in an interrupt
volatile unsigned long lastCoinTime = 0; // Track the last time a coin was detected
const int COIN_VALUE = 1; // Value of each coin in pesos
// Button state variables
bool waterButtonPressed = false;
bool soapButtonPressed = false;
bool blowerButtonPressed = false;
unsigned long waterButtonLastPress = 0;
unsigned long soapButtonLastPress = 0;
unsigned long blowerButtonLastPress = 0;
void setup() {
// Initialize pins
pinMode(coinSlotPin, INPUT_PULLUP);
pinMode(waterButton, INPUT_PULLUP);
pinMode(soapButton, INPUT_PULLUP);
pinMode(blowerButton, INPUT_PULLUP);
pinMode(relayWater, OUTPUT);
pinMode(relaySoap, OUTPUT);
pinMode(relayBlower, OUTPUT);
pinMode(buzzer, OUTPUT);
// Initialize relays to OFF state (HIGH for low-trigger relays)
digitalWrite(relayWater, HIGH);
digitalWrite(relaySoap, HIGH);
digitalWrite(relayBlower, HIGH);
// Initialize LCD
lcd.init();
lcd.backlight();
displayInitialScreen();
// Attach interrupt for coin slot with debouncing logic
attachInterrupt(digitalPinToInterrupt(coinSlotPin), coinInserted, FALLING);
}
void loop() {
unsigned long currentMillis = millis();
// Handle initial screen and blinking "Insert Coin" message
if (balance == 0 && waterTime == 0 && soapTime == 0 && blowerTime == 0) {
if (!screenInitialized) {
displayInitialScreen();
screenInitialized = true;
}
// Independent blinking for --Insert Coin!--
if (currentMillis - lastInsertCoinBlinkTime > BLINK_INTERVAL) {
lastInsertCoinBlinkTime = currentMillis;
showInsertCoin = !showInsertCoin;
blinkInsertCoin();
}
} else {
screenInitialized = false;
}
// Handle coin insertion
if (coinsInserted > 0) {
balance += coinsInserted * COIN_VALUE; // Add the value of inserted coins to the balance
coinsInserted = 0; // Reset the coin counter
displayActiveScreen(); // Update the display
}
// Check buzzer timing
checkBuzzerTiming();
// Update timers every second
if (currentMillis - lastUpdateTime >= 1000) {
lastUpdateTime = currentMillis;
updateTime();
}
// Handle button presses and blinking "Press a Button" message
if (balance >= 5 || waterTime > 0 || soapTime > 0 || blowerTime > 0) {
if (currentMillis - lastButtonBlinkTime > BLINK_INTERVAL) {
lastButtonBlinkTime = currentMillis;
showPressButton = !showPressButton;
blinkPressButton();
}
handleButton(waterButton, relayWater, waterTime, waterActive, waterPaused, waterPauseCount, DEFAULT_WATER_TIME, waterButtonPressed, waterButtonLastPress);
handleButton(soapButton, relaySoap, soapTime, soapActive, soapPaused, soapPauseCount, DEFAULT_SOAP_TIME, soapButtonPressed, soapButtonLastPress);
handleButton(blowerButton, relayBlower, blowerTime, blowerActive, blowerPaused, blowerPauseCount, DEFAULT_BLOWER_TIME, blowerButtonPressed, blowerButtonLastPress);
}
// Handle blinking for paused timers
handlePausedBlinking();
// Ensure --Insert Coin!-- is displayed when balance is 0
if (balance == 0) {
if (currentMillis - lastInsertCoinBlinkTime > BLINK_INTERVAL) {
lastInsertCoinBlinkTime = currentMillis;
showInsertCoin = !showInsertCoin;
blinkInsertCoin();
}
}
}
// Interrupt Service Routine (ISR) for coin insertion
void coinInserted() {
unsigned long currentTime = millis();
// Debounce the interrupt
if (currentTime - lastCoinTime > COIN_DEBOUNCE_TIME) {
coinsInserted++; // Increment the coin counter
lastCoinTime = currentTime; // Update the last coin detection time
}
}
// Non-blocking button handling
void handleButton(int button, int relay, int &time, bool &active, bool &paused, int &pauseCount, int defaultTime, bool &buttonPressed, unsigned long &lastPressTime) {
unsigned long currentMillis = millis();
// Check if the button is pressed
if (digitalRead(button) == LOW) {
if (!buttonPressed && (currentMillis - lastPressTime > BUTTON_DEBOUNCE_TIME)) {
buttonPressed = true;
lastPressTime = currentMillis;
if (!active && balance >= 5) {
balance -= 5;
time += defaultTime;
active = true;
paused = false;
pauseCount = 0;
digitalWrite(relay, LOW);
} else if (active) {
if (!paused && pauseCount < MAX_PAUSE_COUNT) {
paused = true;
pauseCount++;
digitalWrite(relay, HIGH);
} else if (paused) {
paused = false;
digitalWrite(relay, LOW);
}
}
updateTimeDisplay();
}
} else {
buttonPressed = false;
}
}
// Check and sound buzzer at specific intervals
void checkBuzzerTiming() {
unsigned long currentMillis = millis();
if (currentMillis - lastBuzzerTime >= BUZZER_CHECK_INTERVAL) {
lastBuzzerTime = currentMillis;
if (waterActive && !waterPaused) checkAndSoundBuzzer(waterTime);
if (soapActive && !soapPaused) checkAndSoundBuzzer(soapTime);
if (blowerActive && !blowerPaused) checkAndSoundBuzzer(blowerTime);
}
}
void checkAndSoundBuzzer(int timeLeft) {
if (timeLeft == 10 || timeLeft == 6 || timeLeft == 2) {
soundBuzzer();
}
}
void soundBuzzer() {
tone(buzzer, 2000, 500); // 2000 Hz for 500ms
}
void updateTime() {
bool displayNeedsUpdate = false;
if (waterActive && !waterPaused && waterTime > 0) {
waterTime--;
displayNeedsUpdate = true;
}
if (soapActive && !soapPaused && soapTime > 0) {
soapTime--;
displayNeedsUpdate = true;
}
if (blowerActive && !blowerPaused && blowerTime > 0) {
blowerTime--;
displayNeedsUpdate = true;
}
if (waterTime == 0 && waterActive) {
waterActive = false;
digitalWrite(relayWater, HIGH);
}
if (soapTime == 0 && soapActive) {
soapActive = false;
digitalWrite(relaySoap, HIGH);
}
if (blowerTime == 0 && blowerActive) {
blowerActive = false;
digitalWrite(relayBlower, HIGH);
}
if (balance == 0 && waterTime == 0 && soapTime == 0 && blowerTime == 0) {
displayInitialScreen();
} else if (displayNeedsUpdate) {
updateTimeDisplay();
}
}
void displayInitialScreen() {
lcd.setCursor(3, 0);
lcd.print(" 3in1 CARWASH");
lcd.setCursor(0, 2);
lcd.print("WATER SOAP BLOWER");
lcd.setCursor(0, 3);
lcd.print("00:00 00:00 00:00");
lcd.setCursor(0, 1);
lcd.print(" --Insert Coin!--");
}
void blinkInsertCoin() {
lcd.setCursor(0, 1);
if (showInsertCoin) {
lcd.print(" --Insert Coin!-- ");
} else {
lcd.print(" ");
}
}
void displayActiveScreen() {
lcd.setCursor(3, 0);
if (balance > 0) {
lcd.print("PRESS A BUTTON");
} else {
lcd.print(" 3in1 CARWASH ");
}
lcd.setCursor(2, 1);
if (balance > 0) {
lcd.print(" Balance: ");
lcd.print(balance);
} else {
lcd.print("--Insert Coin!--");
}
lcd.setCursor(0, 2);
lcd.print("WATER SOAP BLOWER");
updateTimeDisplay();
blinkPressButton();
}
void blinkPressButton() {
lcd.setCursor(3, 0);
if (balance > 0) {
lcd.print(showPressButton ? "PRESS A BUTTON" : " ");
} else {
lcd.print(" 3in1 CARWASH ");
}
}
void updateTimeDisplay() {
lcd.setCursor(2, 1);
if (balance > 0) {
lcd.print(" Balance: ");
lcd.print(balance);
} else {
// Independent blinking for --Insert Coin!--
if (millis() - lastInsertCoinBlinkTime > BLINK_INTERVAL) {
lastInsertCoinBlinkTime = millis();
showInsertCoin = !showInsertCoin;
}
if (showInsertCoin) {
lcd.print("--Insert Coin!--");
} else {
lcd.print(" ");
}
}
lcd.print(" ");
lcd.setCursor(0, 3);
displayTime(waterTime, waterPaused, 0, waterBlinkState, waterLastBlinkTime);
lcd.setCursor(7, 3);
displayTime(soapTime, soapPaused, 7, soapBlinkState, soapLastBlinkTime);
lcd.setCursor(14, 3);
displayTime(blowerTime, blowerPaused, 14, blowerBlinkState, blowerLastBlinkTime);
}
void displayTime(int seconds, bool paused, int column, bool &blinkState, unsigned long &lastBlinkTime) {
if (paused) { // Only apply blinking logic if the timer is paused
if (millis() - lastBlinkTime > BLINK_INTERVAL) {
lastBlinkTime = millis();
blinkState = !blinkState;
}
if (blinkState) {
lcd.setCursor(column, 3);
lcd.print(" ");
} else {
lcd.setCursor(column, 3);
lcd.print(formatTime(seconds));
}
} else { // If not paused, display the time normally
lcd.setCursor(column, 3);
lcd.print(formatTime(seconds));
}
}
String formatTime(int seconds) {
int mins = seconds / 60;
int secs = seconds % 60;
char buf[6];
sprintf(buf, "%02d:%02d", mins, secs);
return String(buf);
}
void handlePausedBlinking() {
if (waterPaused) {
if (millis() - waterLastBlinkTime > BLINK_INTERVAL) {
waterLastBlinkTime = millis();
waterBlinkState = !waterBlinkState;
lcd.setCursor(0, 3);
displayTime(waterTime, waterPaused, 0, waterBlinkState, waterLastBlinkTime);
}
}
if (soapPaused) {
if (millis() - soapLastBlinkTime > BLINK_INTERVAL) {
soapLastBlinkTime = millis();
soapBlinkState = !soapBlinkState;
lcd.setCursor(7, 3);
displayTime(soapTime, soapPaused, 7, soapBlinkState, soapLastBlinkTime);
}
}
if (blowerPaused) {
if (millis() - blowerLastBlinkTime > BLINK_INTERVAL) {
blowerLastBlinkTime = millis();
blowerBlinkState = !blowerBlinkState;
lcd.setCursor(14, 3);
displayTime(blowerTime, blowerPaused, 14, blowerBlinkState, blowerLastBlinkTime);
}
}
}
Is it different from what you posted originally? If so say what you've changed, why you changed it, and how it works now. I told you I used your original code and it did nothing beyond counting coins badly. What works and does not work now, or for you?
Are you sitting in front of relays, buttons, a coin mechanism and an LCD display all wired up and awaiting software? You are going about this backwards. Get the software working with serial input and output, pushbuttons and LEDs. You might even start with nothing but serial input and output.
You might benefit from knowing that what you are ending up with can be expressed in software using finite state machinery:
Yet another Finite State Machine introduction
You shoukd also learn about the IPO model, read about it in the abstract here:
Please look for question marks and try to provide information. Not videos, your own thinking and observations. Please share your design documents.
The rest of my post is just me ranting and in a bad mood, I've had too much of one thing and not enough of another just now.
Never mind, good luck.
The video is interesting. I can tell it was not written by chatGPT or deepSick, rather humans who were probably very accomplished engineers or advanced students.
Your other remarks allow me to conclude that you are in very over your head, and the liquid you have deep slight isn't even water.
This project is too ambitious.
To offer a video instead of design documents that show your thinking, or even just say. In words. Not too many.
What your desired goal is.
If you are using the video as an operational specification, the next work product you create should be a real detailed design. For just the software, this has many possibilities.
When you present this, you won't be showing a video, and it will be something more than the finiched device.
Is this for commercial purposes? You shouldn't be asking for help, you should be paying for it.
Is this for school? You shouldn't be using AI or asking strangers to debug your code.
If this is for school, you have been sadly led to a point where you are being asked to do something you are just not capable of. Unless you have a year to do this, starting from where you are is just not realistic. It it too late to get a refund of your tuition?
a7
Insufficient detail. Did it compile? If not, post the verbose error report. If no errors, what exactly happened?
You didn’t answer my question
“ Is this your first substantial project? “. I’m guessing Yes.
I have replaced the sketch in my project with @nicole0229's (or whomever's) latest code in #24.
To my surprise and delight, it appears to function rationally. Without knowing exactly what it is supposed to do, I will accept its behaviour as the desired outcome.
I will refrain from commenting on the design of the UI and UX. Other than to say I get dizzy when I play with it.
Only by providing all inputs as clean debounced logic signals was I able to use it.
If regular buttons are used for water, soap and blower, their bouncing makes reliable operation impossible. I cannot look into this, and unless things have changed from the first posted code, it may be tricky to ferret out just why the code that seems to be where any debouncing is done is insufficient.
The hardware debounced coin button I have counts two coins per press, this should be easy to correct.
The button handling was one of the first things I looked at and it was spread out and intermixed with other logic; pin-pointing any places to change things for the better was looking to be a bit too much involved.
HTH it looks like from a software standpoint you maybe close. Focus on the button bouncing which is a major problem and an impediment to seeing what remains for logic flaws.
a7
Here's @nicole0229's button handling logic stripped of all the stuff that makes verifying its proper operation, or finding the flaw, so hard.
Try to make the button toggle the LED. Until you can make this sketch work, forget about fixing your buttonhandling.
Kinda frustrating:
// https://wokwi.com/projects/424431180303060993
const byte theButton = 3;
const byte theLED = 6;
# define PRESST LOW
void setup() {
Serial.begin(115200);
Serial.println("\nbounce house\n");
pinMode(theButton, INPUT_PULLUP);
pinMode(theLED, OUTPUT);
}
unsigned long currentMillis;
void loop()
{
currentMillis = millis();
bogusButtonHandler();
}
int counter;
bool buttonPressed;
unsigned long lastPressTime;
void bogusButtonHandler()
{
bool buttonState = digitalRead(theButton) == PRESST;
if (!buttonState) {
buttonPressed = false;
return;
}
if (!buttonPressed && currentMillis - lastPressTime > 100) {
buttonPressed = true;
lastPressTime = currentMillis;
// count and report button press, toggle the LED
counter++;
Serial.print("press number ");
Serial.print(counter);
Serial.println(" detected.");
digitalWrite(theLED, digitalRead(theLED) == HIGH ? LOW : HIGH);
}
}
HTH
a7
Closure's always appreciated, so what's the latest status of your project? . Is it all sorted for you now, following @alto777's latest posts?
Also, I'm still curious: is it a school/college project? Looks very similar to the 87-post thread 'Coin counter project for school' here:
by @trixie0229
Rather similar ID to yours, @nicole0229, and starts with similar wording "I just want to ask for help with my project which is a 3 in 1 carwash vending machine."
Has me wondering if that was your thread too? Or if not connected, did you study it for possible help?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.