Skip to content

Commit f3191b1

Browse files
committed
Added the correct read CTL and write MOD. But there is a problem with the A0 read.
1 parent 7d39d6b commit f3191b1

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

ldc500/ldc500.ino

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
A (slope) = 6,979088703376868e-01 +/- 1,292424325833072e-03
1515
*/
1616

17-
#include <dht.h>
18-
dht DHT;
17+
//#include <dht.h>
18+
//dht DHT;
1919

2020
unsigned long serialNumber = 302432729;
2121
float time;
@@ -25,30 +25,34 @@ float B=21.5804876;
2525

2626
float kLDC500 = 50.0; // mA/V
2727

28-
const int laserPin = 13;
29-
const int laserIn = 11;
30-
const int laserOut = A0;
31-
const int dht22Pin = 5;
28+
const int laserREM = 13;
29+
const int laserMod = 11;
30+
const int laserCTL = A0;
31+
//const int dht22Pin = 5;
3232

3333
String inputString = ""; // a string to hold incoming data
3434
boolean stringComplete = false; // whether the string is complete
3535

3636
void setup() {
37-
pinMode(laserPin, OUTPUT);
37+
pinMode(laserREM, OUTPUT);
38+
pinMode(laserMod, OUTPUT);
3839
Serial.begin(115200);
3940
// reserve 200 bytes for the inputString:
4041
inputString.reserve(200);
4142
}
4243

4344
void setCurrent(float i) {
44-
// 5/256 = 0,01953125
45-
int iDigit = 0;
46-
analogWrite(laserPin, iDigit);
45+
if (i > 100.00) { i = 100.00; }
46+
// 255/5 * i/50
47+
int iDigit = i*2.55;
48+
analogWrite(laserMod, iDigit);
49+
Serial.println("OK\r");
4750
}
4851

4952
float getVoltage() {
50-
int ctlOut = analogRead(laserOut);
53+
int ctlOut = analogRead(A0);
5154
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
55+
Serial.println(analogRead(A0));
5256
return ctlOut*(5.0 / 1023.0); // voltage
5357
}
5458

@@ -76,18 +80,18 @@ void loop() {
7680
// Status of 4 LEDs
7781
if (inputString.startsWith("leds?")) {
7882
// POWER ON + LASER ON + LASER LOCK + ERROR = 1 + 2 + 4 + 8
79-
int leds = 1+digitalRead(laserPin)*6;
83+
int leds = 1+digitalRead(laserREM)*6;
8084
Serial.println(leds);
8185
// Laser ENABLE/DISABLE/STATE
8286
} else if (inputString.startsWith("l")) {
8387
if (inputString.substring(1,2) == "0") {
84-
digitalWrite(laserPin,LOW);
88+
digitalWrite(laserREM,LOW);
8589
Serial.println("OK\r");
8690
} else if (inputString.substring(1,2) == "1") {
87-
digitalWrite(laserPin,HIGH);
91+
digitalWrite(laserREM,HIGH);
8892
Serial.println("OK\r");
8993
} else if (inputString.substring(1,2) == "?") {
90-
Serial.println(digitalRead(laserPin));
94+
Serial.println(digitalRead(laserREM));
9195
} else {
9296
Serial.print("Syntax Error: ");
9397
Serial.println(inputString);
@@ -111,34 +115,34 @@ void loop() {
111115
setCurrent(fpi);
112116
}
113117
// DHT22 Sensor TEMP/HUM
114-
} else if (inputString.startsWith("d")) {
115-
int chk = DHT.read22(dht22Pin);
116-
switch (chk) {
117-
case DHTLIB_OK:
118-
//Serial.print("OK,\t");
119-
break;
120-
case DHTLIB_ERROR_CHECKSUM:
121-
Serial.print("Checksum error,\t");
122-
break;
123-
case DHTLIB_ERROR_TIMEOUT:
124-
Serial.print("Time out error,\t");
125-
break;
126-
default:
127-
Serial.print("Unknown error,\t");
128-
break;
129-
}
130-
if (inputString.substring(1,3) == "t?") {
131-
Serial.println(DHT.temperature, 1);
132-
} else if (inputString.substring(1,3) == "h?") {
133-
Serial.println(DHT.humidity, 1);
134-
} else if (inputString.substring(1,2) == "?") {
135-
Serial.print(DHT.humidity, 1);
136-
Serial.print("; ");
137-
Serial.println(DHT.temperature, 1);
138-
} else {
139-
Serial.print("Syntax Error: ");
140-
Serial.println(inputString);
141-
}
118+
// } else if (inputString.startsWith("d")) {
119+
// int chk = DHT.read22(dht22Pin);
120+
// switch (chk) {
121+
// case DHTLIB_OK:
122+
// //Serial.print("OK,\t");
123+
// break;
124+
// case DHTLIB_ERROR_CHECKSUM:
125+
// Serial.print("Checksum error,\t");
126+
// break;
127+
// case DHTLIB_ERROR_TIMEOUT:
128+
// Serial.print("Time out error,\t");
129+
// break;
130+
// default:
131+
// Serial.print("Unknown error,\t");
132+
// break;
133+
// }
134+
// if (inputString.substring(1,3) == "t?") {
135+
// Serial.println(DHT.temperature, 1);
136+
// } else if (inputString.substring(1,3) == "h?") {
137+
// Serial.println(DHT.humidity, 1);
138+
// } else if (inputString.substring(1,2) == "?") {
139+
// Serial.print(DHT.humidity, 1);
140+
// Serial.print("; ");
141+
// Serial.println(DHT.temperature, 1);
142+
// } else {
143+
// Serial.print("Syntax Error: ");
144+
// Serial.println(inputString);
145+
// }
142146
// Serial Number
143147
} else if (inputString.startsWith("sn?")) {
144148
Serial.println(serialNumber);

0 commit comments

Comments
 (0)