Hey,
I'm doing this project where the goal is to control the power of a light source through labview. I have both of those code but at the end of the day I can never contol the light anyone can help me ?
float labviewFLT = 0;
const byte numChars = 32;
char labviewSTR[numChars];
int pwm = 4; // assigns pin 4 to variable pwm
int t1 = 0; // declares variable t1
int t2 = 0; // declares variable t2
float a = 5;
float b = 1000;
int c = 1000;
boolean newData = false;
void setup() {
Serial.begin(9600);
pinMode(pwm,OUTPUT);
}
void loop() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
labviewSTR[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
labviewSTR[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
if (newData) {
labviewFLT = atof(labviewSTR);
t2 = labviewFLT/(a/b); // reads the voltage at A0 and saves in t2; // reads the voltage at A0 and saves in t2
t1= c-t2; // subtracts t2 from 1000 ans saves the result in t1
digitalWrite(pwm, HIGH); // sets pin 12 HIGH
delayMicroseconds(t1); // waits for t1 uS (high time)
digitalWrite(pwm, LOW); // sets pin 12 LOW
delayMicroseconds(t2); // waits for t2 uS (low time)
newData = false;
}
else {
digitalWrite(pwm,LOW);
}
}
And for labview :
I'm really sorry if this seems to be an obvious problem but I'm clearly not talented at electricity or programming
Thanks a lot