=>[[helvepic32:|HelvePic32]] ==== Analog Input ==== Der PIC32MX250F128B hat 9 analoge Input Pins, welche als A0 ... A8 vordefiniert sind. Der Einfachheit des Codes zu Liebe bleiben wir bei der Notation mit dem oben eingeführten Pin-Arrays. Dazu schliessen wir ein Potentiometer (10 kOhm) an GND und 3.3V an. Den Mittenabgriff geben wir auf der linken Seite auf den Pin 2, den ersten analogen Input dieser Seite (siehe Diagramm oben).Das Auslesen des analogen Inputs geht wie beim Arduino: /* Code based on Analog Input Created by David Cuartielles Modified 4 Sep 2010 by Tom Igoe modified 31 Dec 2014 by Mathias Wilhelm This example code is in the public domain. http://arduino.cc/en/Tutorial/AnalogInput */ const uint8_t LEFT=0; const uint8_t RIGHT=1; uint8_t nP[2][8] = {{0,17, 9,10,11,12,13,14},{18,17, 1, 2, 3, 6, 7, 8}}; // pins of version 1.0 using DP32 bootloader int sensorPin = nP[LEFT][2]; // select the input pin for the potentiometer int ledPin = nP[RIGHT][2]; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setup() { pinMode(ledPin, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); digitalWrite(ledPin, HIGH); delay(sensorValue); digitalWrite(ledPin, LOW); delay(sensorValue); } Es bietet sich natürlich an, diesen Sketch mit dem Servo Sketch zu verbinden und den Servo über den Poti zu steuern: {{:chipkit:helvepic32_servopoti_sml.png?600|}} /* Control a Servo via a poti Created 31 Dec 2014 by Mathias Wilhelm */ const uint8_t LEFT=0; const uint8_t RIGHT=1; uint8_t nP[2][8] = {{0,17, 9,10,11,12,13,14},{18,17, 1, 2, 3, 6, 7, 8}}; // pins of version 1.0 using DP32 bootloader #include int pos = 0; // variable to store the servo position, in microseconds const int pin = nP[RIGHT][4]; // Choose _any_ pin number on your board int sensorPin = nP[LEFT][2]; // select the input pin for the potentiometer int ledPin = nP[RIGHT][2]; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setup() { pinMode(ledPin, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); pos = map(sensorValue,0, 1023, 1000, 2000); SoftPWMServoServoWrite(pin, pos); delay(25); } =>[[helvepic32:|HelvePic32]]