the system will be activated by a microswitch on the throttle body and then the arduino is tasked to pulse the solenoids via a mosfet from a 25% duty cycle to 100% over 2.5 seconds while the switch is activated.
now, the circuit I believe is very simple. but the coding I may have a struggle to understand fully.
so, I have taken some of the example codes and tried to make my own code out of them to make it do what I want it to.
can somebody check If I am on the right path?
here is what I did.
Code: Select all
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const ledPin = 9; // Mosfet connected to digital pin 9
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// fade in from 25% to 100% in increments of 5 points:
for(int fadeValue = 51 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 2.5 seconds to see the effect
delay(2500); ;
}
else {
// turn mosfet off:
digitalWrite(ledPin, LOW);