Hello all here's the first of many daft questions I imagine I will be asking as I learn to program a little better.
I’m doing a bit of work on an mbed microprocessor and I've got a simple bit of code that allows an LED light to flash on and off.
What I want to do is change the speed at which it flashes via means of a push button (hold the button down it’ll flash quickly release the button and the LED will flash more slowly).
#include "mbed.h"
DigitalOut led1 (LED1);
DigitalOut power (p7); //i'm using this for the signal going into p9 which is controlled by a switch.
DigitalIn button (p9);
float x; // light flashing speed variable
int main() {
while(1) { //infinite loop
power = 1; //power going to the switch between p7 and p9 is on.
led1=1;
wait("x"); //led flash speed and the bit i'm struggling with at the moment :(
led1=0;
wait("x");
if (button == 1) {
x=0.5;
}
elseif (button == 0){
x=1;
}
}
}
The issue I’m having is that I’m not sure how to make the “wait” functions read the “x” in the brackets next to them (IE so that when the x is defined as 0.5 the “wait” function reads it as 0.5 and the same thing for when x is defined as 1).
I’m not sure how exclusive to the mbed wait functions are but when they’re written out normally they look like this.
wait(0.5); // this will make the code wait half a second.
Pushing the button and releasing it changes the” x” just fine but I’m not sure what I have to put to make it read what “x” represents.
Any help that can be suggested is much appreciated.
All the best