Re: Elektronik Bastelei mit Arduino (Selbstbau Tacho, DZM et
Verfasst: 22. Feb 2015
ich dachte, das sei ein sammelfred....
ich hab da noch jemad mit ins boot genommen, aber ich/wir kommen da nicht weiter.
der ntc ist mit einem 680 ohm widerstand als spannungsteiler geschaltet.
(°C) (Ohm)
40 417
50 269
60 179
70 124
80 88
90 64
100 48
110 36
120 28
130 22
140 18
150 15
kann da ein wissender mal über den sketch schaun?
wurde mit der arduino IDE geschrieben
#define DEBUG
#define LED_ONE 10
#define LED_TWO 5
#define analogPin 2
#define updateTime 1000
#define BLUE 0
#define GREEN 1
#define RED 2
#define RED_BLINK 3
int currentMode = 0;
int currentResistance = 0;
long lastUpdate = 0;
void setLED(int led, int r, int g, int b) {
analogWrite(led, r);
analogWrite(led + 1, g);
analogWrite(led + 2, b);
}
void enableLED(int led) {
for (int col = 0; col < 3; col++) {
Serial.write(led+col);
pinMode(led + col, OUTPUT);
}
}
void startSequence(int led) {
for (int col = 0; col < 4; col++) {
setLED(led, col == 0 ? 255 : 0, col == 1 ? 255 : 0, col == 2 ? 255 : 0);
delay(500);
}
}
int getBlinkmode(int temp) {
if (temp <= 60) {
return BLUE;
} else if (temp >= 140) {
return RED_BLINK;
} else if (temp >= 120) {
return RED;
} else {
return GREEN;
}
}
int measureResistance() {
if (millis() - lastUpdate > updateTime) {
int raw = 0;
int Vin = 5;
float Vout = 0;
float R1 = 10;
float R2 = 0;
float buffer = 0;
raw = analogRead(analogPin); // Reads the Input PIN
Vout = (5.0 / 1023.0) * raw; // Calculates the Voltage on th Input PIN
buffer = (Vin / Vout) - 1;
R2 = R1 / buffer;
Serial.print("Voltage: "); //
Serial.println(Vout); // Outputs the information
Serial.print("R2: "); //
Serial.println(R2); //
lastUpdate = millis();
}
return 0;
}
void handleBlinkmode(int led, int mode) {
switch(mode) {
case BLUE:
setLED(led, 0, 0, 255);
break;
case GREEN:
setLED(led, 0, 255, 0);
break;
case RED:
setLED(led, 255, 0, 0);
break;
case RED_BLINK:
setLED(led, millis() % 15 >= 7 ? 255 : 0, 0, 0);
break;
}
}
void setup() {
#ifdef DEBUG
Serial.begin(9600);
#endif
enableLED(LED_ONE);
startSequence(LED_ONE);
}
void loop() {
int res = measureResistance();
currentResistance = res != 0 ? res : currentResistance;
currentMode = getBlinkmode(currentResistance);
handleBlinkmode(LED_ONE, currentMode);
/* #ifdef DEBUG
Serial.print(res);
Serial.print("\t");
Serial.print(currentResistance);
Serial.print("\t");
Serial.println(currentMode);
#endif*/
}

ich hab da noch jemad mit ins boot genommen, aber ich/wir kommen da nicht weiter.
der ntc ist mit einem 680 ohm widerstand als spannungsteiler geschaltet.
(°C) (Ohm)
40 417
50 269
60 179
70 124
80 88
90 64
100 48
110 36
120 28
130 22
140 18
150 15
kann da ein wissender mal über den sketch schaun?
wurde mit der arduino IDE geschrieben
#define DEBUG
#define LED_ONE 10
#define LED_TWO 5
#define analogPin 2
#define updateTime 1000
#define BLUE 0
#define GREEN 1
#define RED 2
#define RED_BLINK 3
int currentMode = 0;
int currentResistance = 0;
long lastUpdate = 0;
void setLED(int led, int r, int g, int b) {
analogWrite(led, r);
analogWrite(led + 1, g);
analogWrite(led + 2, b);
}
void enableLED(int led) {
for (int col = 0; col < 3; col++) {
Serial.write(led+col);
pinMode(led + col, OUTPUT);
}
}
void startSequence(int led) {
for (int col = 0; col < 4; col++) {
setLED(led, col == 0 ? 255 : 0, col == 1 ? 255 : 0, col == 2 ? 255 : 0);
delay(500);
}
}
int getBlinkmode(int temp) {
if (temp <= 60) {
return BLUE;
} else if (temp >= 140) {
return RED_BLINK;
} else if (temp >= 120) {
return RED;
} else {
return GREEN;
}
}
int measureResistance() {
if (millis() - lastUpdate > updateTime) {
int raw = 0;
int Vin = 5;
float Vout = 0;
float R1 = 10;
float R2 = 0;
float buffer = 0;
raw = analogRead(analogPin); // Reads the Input PIN
Vout = (5.0 / 1023.0) * raw; // Calculates the Voltage on th Input PIN
buffer = (Vin / Vout) - 1;
R2 = R1 / buffer;
Serial.print("Voltage: "); //
Serial.println(Vout); // Outputs the information
Serial.print("R2: "); //
Serial.println(R2); //
lastUpdate = millis();
}
return 0;
}
void handleBlinkmode(int led, int mode) {
switch(mode) {
case BLUE:
setLED(led, 0, 0, 255);
break;
case GREEN:
setLED(led, 0, 255, 0);
break;
case RED:
setLED(led, 255, 0, 0);
break;
case RED_BLINK:
setLED(led, millis() % 15 >= 7 ? 255 : 0, 0, 0);
break;
}
}
void setup() {
#ifdef DEBUG
Serial.begin(9600);
#endif
enableLED(LED_ONE);
startSequence(LED_ONE);
}
void loop() {
int res = measureResistance();
currentResistance = res != 0 ? res : currentResistance;
currentMode = getBlinkmode(currentResistance);
handleBlinkmode(LED_ONE, currentMode);
/* #ifdef DEBUG
Serial.print(res);
Serial.print("\t");
Serial.print(currentResistance);
Serial.print("\t");
Serial.println(currentMode);
#endif*/
}