My first Arduino project – Pulse

My first Arduino project – Pulse

OK, so it’s not really a project. And the circuit is just that used in the ARDX manual for CIRC-07. But the program is mine! It’s not very exciting, but then I expect first projects rarely are.

If you can’t tell from the video, the LED pulses and the two buttons control the speed of the pulse.

int ledPin = 9;
int inputPin1 = 3;
int inputPin2 = 2;
int val = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
}

int value = 0;
int direction = 1;
int speed = 5;

void loop(){
if (digitalRead(inputPin1) == LOW) {
speed++;
while (digitalRead(inputPin1) == LOW) {}
}
if (digitalRead(inputPin2) == LOW) {
speed--;
while (digitalRead(inputPin2) == LOW) {}
}

value = value + direction;
if ((value > 254) || (value < 1)) { direction = direction * -1; } value = constrain(value, 0, 255); analogWrite(ledPin, value); if (speed < 1) {speed = 1; } if (speed > 30) {speed = 30; }
delay(speed);

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.