I have no experience, knowledge, or understanding of coding or programing, but I would like to learn some. I found a post about building a soap dispenser using a Nano. The instructions came with the code to upload on the board, but I am getting errors. Can anyone help fix it or show me how too?
This is the code that was given:
<p>// timings. middle button computes the average between max and min.
// pumps start when the button is first pushed.
// time starts when the button is released.
#define SOAP_MIN_DURATION 1000
#define SOAP_MAX_DURATION 3000
#define SOFT_MIN_DURATION 1000
#define SOFT_MAX_DURATION 3000</p><p>// button pins. 1 is shortest duration.
#define SOAP_1 2
#define SOAP_2 3
#define SOAP_3 4
#define SOFT_1 5
#define SOFT_2 6
#define SOFT_3 7
#define MOTOR_SOAP 8
#define MOTOR_SOFT 9</p><p>void setup() {
pinMode(SOAP_1, INPUT_PULLUP);
pinMode(SOAP_2, INPUT_PULLUP);
pinMode(SOAP_3, INPUT_PULLUP);
pinMode(SOFT_1, INPUT_PULLUP);
pinMode(SOFT_2, INPUT_PULLUP);
pinMode(SOFT_3, INPUT_PULLUP);
pinMode(MOTOR_SOAP, OUTPUT);
pinMode(MOTOR_SOFT, OUTPUT);
}</p><p>uint32_t current_time;
uint32_t next_time;
uint32_t soap_off_time = 0;
uint32_t soft_off_time = 0;</p><p>void loop() {
next_time = millis();
if (next_time < current_time) {
// time has rolled over. congratulations on leaving this plugged in for 49.7 days.
soap_off_time = 0;
soft_off_time = 0;
}
current_time = next_time;</p><p> // check if the soap pump should be running
if (soap_off_time > current_time) {
digitalWrite(MOTOR_SOAP, HIGH);
} else {
digitalWrite(MOTOR_SOAP, LOW);
}</p><p> // check if the softener pump should be running
if (soft_off_time > current_time) {
digitalWrite(MOTOR_SOFT, HIGH);
} else {
digitalWrite(MOTOR_SOFT, LOW);
}</p><p> // check if we need to do anything for any of the buttons
if (!digitalRead(SOAP_1)) {
soap_off_time = current_time + SOAP_MIN_DURATION;
}
if (!digitalRead(SOAP_2)) {
soap_off_time = current_time + (SOAP_MIN_DURATION + SOAP_MAX_DURATION) / 2;
}
if (!digitalRead(SOAP_3)) {
soap_off_time = current_time + SOAP_MAX_DURATION;
}
if (!digitalRead(SOFT_1)) {
soft_off_time = current_time + SOFT_MIN_DURATION;
}
if (!digitalRead(SOFT_2)) {
soft_off_time = current_time + (SOFT_MIN_DURATION + SOFT_MAX_DURATION) / 2;
}
if (!digitalRead(SOFT_3)) {
soft_off_time = current_time + SOFT_MAX_DURATION;
}
}
</p>
This is the error messages:
Arduino: 1.8.13 (Mac OS X), Board: "Arduino Nano, ATmega328P"
sketch_jan21a:1:1: error: expected unqualified-id before '<' token
<p>// timings. middle button computes the average between max and min.
// pumps start when the button is first pushed.
^
sketch_jan21a:16:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(SOAP_2, INPUT_PULLUP);
^
sketch_jan21a:17:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(SOAP_3, INPUT_PULLUP);
^
sketch_jan21a:18:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(SOFT_1, INPUT_PULLUP);
^
sketch_jan21a:19:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(SOFT_2, INPUT_PULLUP);
^
sketch_jan21a:20:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(SOFT_3, INPUT_PULLUP);
^
sketch_jan21a:21:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(MOTOR_SOAP, OUTPUT);
^
sketch_jan21a:22:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(MOTOR_SOFT, OUTPUT);
^
sketch_jan21a:23:2: error: expected unqualified-id before '<' token
}</p><p>uint32_t current_time;
^
sketch_jan21a:26:28: error: expected unqualified-id before '<' token
uint32_t soft_off_time = 0;</p><p>void loop() {
^
exit status 1
expected unqualified-id before '<' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.