Following forum advice to stop trying to modify code for my first project and instead make it from scratch, here is my attempt. I split it into two "methods". I'm looking for structural advice. Like pointing out if tried to put code in the wrong area or forgot to declare something. Please tell me if there is a better approach, like using certain libraries. I have included the compiling errors, but I'm not worried about those ATM because I think I can fix them with enough research.
Hardware: UNO R3, Slow Vibration Detector, 1/8w 1K OHM Resistor
const byte RelayPin = 13 ; //names the pin to be used in things like digitalprint(RelayPin, HIGH) instead of using a number that you have to change in a bunch of places. 13 is the onboard LED, used for testing. Because later it will be a different pin, controlling a relay that powers an alarm
const byte VibeSenseOutput = 1 //continuously attempts to power pin 2 through vibration sensor+resistor
const byte VibeSenseInput = 2 //if this gets power, then it means there is a complete circuit through the vibration sensor+resistor. That means there has been a strong impact, and that resets the clock/turns off LED
long currentMillis //these three lines form the basis for a kind of timer
long prevMillis
long interval = 10000
void setup() {
pinMode(RelayPin, OUTPUT) ; //declares pin as inputs/outputs
pinMode(VibeSenseOutput, OUTPUT) ; //declares pin as output
pinMode(VibeSenseInput, INPUT) ; //declares pin as Input
digitalprint(VibeSenseOut, HIGH) ; //sets initial states
digitalprint(VibeSenseIn, LOW) ;
}
void loop() {
VibeSense(); //First "method," goal is to use two declared pins (input and output with vibration sensor and resistor inbetween) to sense an impact
if VibeSenseInput == HIGH && prevState == LOW { //When a NEW impact is detected
digitalprint(RelayPin, LOW) && currentMillis() = millis() //Turn off LED (later relay) off and restart the countdown
}
Countdown(); //Second "method," uses Millis() as a clock to see if a certain time has elapsed. If it has, an onboard LED lights up (later on, it will close a relay)
unsigned long currentMillis;
currentMillis = millis();
if (millis() - prevMillis >= interval) {
//time has expired
digitalprint(RelayPin, HIGH) //Lights the LED (later a relay closes)
}
}
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:uno -build-cache /tmp -build-path /tmp/735570313/build -verbose -libraries /tmp/735570313/custom -libraries /tmp/735570313/pinned /tmp/735570313/dont_try_to_compile
Compiling sketch...
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:14:1: error: expected ',' or ';' before 'const'
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino: In function 'void loop()':
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:32:11: error: 'VibeSense' was not declared in this scope
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:33:6: error: expected '(' before 'VibeSenseInput'
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:41:11: error: 'Countdown' was not declared in this scope
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:44:20: error: 'prevMillis' was not declared in this scope
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:44:34: error: 'interval' was not declared in this scope
/tmp/735570313/dont_try_to_compile/dont_try_to_compile.ino:46:34: error: 'digitalprint' was not declared in this scope
exit status 1