Ich habe das Problem, dass ich an mehreren Analog-Eingängen (4) des Arduino Messungen vornehme und die Resultate als Helligkeit an ebensovielen LEDn ausgeben möchte.
Soll nur eine schnell erfassbare Überwachung sein, damit Schwankungen erkannt werden können.
Der Sketch dazu ist denkbar einfach(siehe Anhang).
1 Kanal ist durch einen Zähler ersetzt (zu Test).
Es werden auch noch die Zahlenwerte am ser. Ausgang ausgegeben - hat aber nix mit dem Problem zu tun.
Leider bekomme ich aber nur an 3 der 4 PWM Ausgängen einen kontinuierlichen Helligkeitsunterschied, der erste Kanal hat eher ein seltsames Verhalten.
Bin mir sicher, dass softwareseitig alles funktioniert, trotzdem ist ja jede Software mit mehr als 2 Zeilen Code potentiell fehlebehaftet, als ruhig nochmal durchchecken.
Mein Verdacht: es werden nur eine begrenzte Anzahl an PWM unterstützt. Obwohl der Pin als PWM tauglich definiert ist, gibt es irgendwo einen Flaschenhals....
Kann mir jmd weiterhelfen?
Ggf. mit Link auf eventuelle Dokumentation, welche eine solche Einschränkung beschreibt?
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on the value obtained
by analogRead().
The circuit:
- potentiometer
center pin of the potentiometer to the analog input 0
one side pin (either one) to ground
the other side pin to +5V
- LED
anode (long leg) attached to digital output 13
cathode (short leg) attached to ground
- Note: because most Arduinos have a built-in LED attached to pin 13 on the
board, the LED is optional.
created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorPin2 = A1; // select the input pin for the potentiometer
int sensorPin3 = A2; // select the input pin for the potentiometer
int sensorPin4 = A3; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue1 = 0; // variable to store the value coming from the sensor
int sensorValue2 = 0; // variable to store the value coming from the sensor
int sensorValue3 = 0; // variable to store the value coming from the sensor
int sensorValue4 = 0; // variable to store the value coming from the sensor
int LEDout1 = 12;
int LEDout2 = 11;
int LEDout3 = 10;
int LEDout4 = 9;
int IOout = 6;
int NIOout = 5;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
for (int i=0; i< 255; i+=8) { analogWrite(LEDout1,i); delay(30); };
for (int i=0; i< 255; i+=8) { analogWrite(LEDout2,i); delay(30); };
for (int i=0; i< 255; i+=8) { analogWrite(LEDout3,i); delay(30); };
for (int i=0; i< 255; i+=8) { analogWrite(LEDout4,i); delay(30); };
Serial.begin(115200);
}
void loop() {
// read the value from the sensor:
// sensorValue1 = analogRead(sensorPin1);
sensorValue1++;
sensorValue2 = analogRead(sensorPin2);
sensorValue3 = analogRead(sensorPin3);
sensorValue4 = analogRead(sensorPin4);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
analogWrite(LEDout4,sensorValue1>>2);
analogWrite(LEDout3,sensorValue2>>2);
analogWrite(LEDout2,sensorValue3>>2);
analogWrite(LEDout1,sensorValue4>>2);
//delay(100);
Serial.print(sensorValue1&1023);
Serial.print(",");
//delay(50);
Serial.print(sensorValue2&1023);
Serial.print(",");
//delay(50);
Serial.print(sensorValue3&1023);
Serial.print(",");
//delay(50);
Serial.print(sensorValue4&1023);
Serial.println();
delay(50);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
}
@combie:
Jetzt hast mich verwirrt:
IO12 kann ich ganz normal als IO Pin ansprechen (digital), ebenso IO6.
Zumindest hab' ich damit noch keine Probleme gehabt.
Laut Schaltplan sind das auch unabhängige Aussgänge vom µC (PD6 und PD7).
Wie kommst Du auf eine Abhängigkeit der beiden Ausgänge?
Danke ihr Beiden, hat mir geholfen!
Bei "normalem" Betrieb als digital I/O funktionieren die beiden Pins also unabhängig, nur bei PWM von IO6 oder IO12 gibt's Ärger.