Hi guys, I'm new here.
I'm doing C/Arduino at university and I'm having some trouble already (programming is not exactly my forte) so I thought I'd post here as it's generally easier than asking my tutor. (I've already asked him quite a lot and he doesn't explain it very well).
Here is my simple program for switching on an LED. If we change the variable "pulserate" to 0 it shouldn't switch on at all. If we change it to 10 it should stay on all the time and anything inbetween has to make it flash on and off.
I think I'm pretty close to getting this one correct, but 0 and 10 don't work properly.
//Workshop 1 Task 2
int LEDPin = 0;
int pulserate = 0; //0-10 where 0 is off and 10 is on
void setup() {
//initialise the digital pin as an output
pinMode(LEDPin, OUTPUT);
}
void loop() {
if (pulserate == 10) {
digitalWrite(LEDPin, HIGH);
}
else (delay(pulserate*100));
digitalWrite(LEDPin, LOW);
delay(pulserate*100);
digitalWrite(LEDPin, HIGH);
}
I'm doing C/Arduino at university and I'm having some trouble already (programming is not exactly my forte) so I thought I'd post here as it's generally easier than asking my tutor. (I've already asked him quite a lot and he doesn't explain it very well).
Here is my simple program for switching on an LED. If we change the variable "pulserate" to 0 it shouldn't switch on at all. If we change it to 10 it should stay on all the time and anything inbetween has to make it flash on and off.
I think I'm pretty close to getting this one correct, but 0 and 10 don't work properly.
//Workshop 1 Task 2
int LEDPin = 0;
int pulserate = 0; //0-10 where 0 is off and 10 is on
void setup() {
//initialise the digital pin as an output
pinMode(LEDPin, OUTPUT);
}
void loop() {
if (pulserate == 10) {
digitalWrite(LEDPin, HIGH);
}
else (delay(pulserate*100));
digitalWrite(LEDPin, LOW);
delay(pulserate*100);
digitalWrite(LEDPin, HIGH);
}