Hi Erik, Thanks for your reply. Without the while(1) statement the program works fine but when its anywhere in the program it only displays to the line, 6 Channel volt meter.
I have now substituted it "for (int i = 0; i <=2; i++){ " then I insert a "i dash dash" at the end to cheat the same function to make it work but its really weird.
This code works
#include "mbed.h"
#include "Terminal.h"
Terminal term(USBTX, USBRX); // tx, rx
AnalogIn input1(p15);
AnalogIn input2(p16);
AnalogIn input3(p17);
AnalogOut signal(p18);
AnalogIn input5(p19);
AnalogIn input6(p20);
DigitalOut testled(LED1);
int main() {
signal = 0.25; //determins the voltage out signal
term.cls();
term.printf(" 5 Channel voltmeter 1 Generator"); //Only gets to this line
term.locate(1,2);
term.printf("Channel 1= ");
term.locate(30,2);
term.printf("Channel 2= ");
term.locate(1,4);
term.printf("Channel 3= ");
term.locate(30,4);
term.printf("Signal 4= ");
term.locate(1,6);
term.printf("Channel 5= ");
term.locate(30,6);
term.printf("Channel 6= ");
for (int i = 0; i <=2; i++){
float voltage1 = input1*3.3;
float voltage2 = input2*3.3;
float voltage3 = input3*3.3;
float signal4 = signal*3.3; // this is my output
float voltage5 = input5*3.3;
float voltage6 = input6*3.3;
term.locate(15,2);
term.printf("%.3f Vdc",voltage1);
term.locate(45,2);
term.printf("%.3f Vdc",voltage2);
term.locate(15,4);
term.printf("%.3f Vdc",voltage3);
term.locate(45,4);
term.printf("%.3f Vdc",signal4);
term.locate(15,6);
term.printf("%.3f Vdc",voltage5);
term.locate(45,6);
term.printf("%.3f Vdc",voltage6);
wait_ms(100);
i--;
}
}
This code does not, The LED is solid..
#include "mbed.h"
#include "Terminal.h"
Terminal term(USBTX, USBRX); // tx, rx
AnalogIn input1(p15);
AnalogIn input2(p16);
AnalogIn input3(p17);
AnalogOut signal(p18);
AnalogIn input5(p19);
AnalogIn input6(p20);
DigitalOut testled(LED1);
int main() {
signal = 0.25; //determins the voltage out signal
term.cls();
term.printf(" 5 Channel voltmeter 1 Generator"); //Only gets to this line
term.locate(1,2);
term.printf("Channel 1= ");
term.locate(30,2);
term.printf("Channel 2= ");
term.locate(1,4);
term.printf("Channel 3= ");
term.locate(30,4);
term.printf("Signal 4= ");
term.locate(1,6);
term.printf("Channel 5= ");
term.locate(30,6);
term.printf("Channel 6= ");
//for (int i = 0; i <=2; i++){
while(1){
float voltage1 = input1*3.3;
float voltage2 = input2*3.3;
float voltage3 = input3*3.3;
float signal4 = signal*3.3; // this is my output
float voltage5 = input5*3.3;
float voltage6 = input6*3.3;
term.locate(15,2);
term.printf("%.3f Vdc",voltage1);
term.locate(45,2);
term.printf("%.3f Vdc",voltage2);
term.locate(15,4);
term.printf("%.3f Vdc",voltage3);
term.locate(45,4);
term.printf("%.3f Vdc",signal4);
term.locate(15,6);
term.printf("%.3f Vdc",voltage5);
term.locate(45,6);
term.printf("%.3f Vdc",voltage6);
wait_ms(100);
//i--;
}
}
My first simple project failed, Can someone help me understand why this while(1) statment stops my program in its tracks? C is pretty new to me.. Thanks in advanced