There are two examples on the Digispark Wiki...and I had a clarification question or perhaps an enhancement request. Is it possible to reference the pins as P0, P1, P2 etc consistently for analog and digital reads/writes in wiring?
The pins are defined as:
Pin outs:
All pins can be used as Digital I/O
Pin 0 → I2C SDA, PWM (LED on Model B)
Pin 1 → PWM (LED on Model A)
Pin 2 → I2C SCK, Analog
Pin 3 → Analog In (also used for USB+ when USB is in use)
Pin 4 → PWM, Analog (also used for USB- when USB is in use)
Pin 5 → Analog In
In order to enable the internal pull-up on P2 (Analog pin 1) do I have to digitalWrite(2,HI) followed by a pinMode(1,INPUT)?
How do I set Digital pin 1 (P1) as an output and Analog pin 1 (P2) as an input? pinMode(1,INPUT); - per the analog read example would conflict with being able to set per the DigitalRead Example (which would be pinMode(1,OUTPUT)). I'm a little confused here.
Digital Read:
int sensorValue = 0;
void setup() {
//All pins are capable of Digital input
pinMode(0, INPUT); //0 is P0, 1 is P1, 2 is P2, etc - unlike the analog inputs, for digital inputs the pin number matches
}
void loop() {
sensorValue = digitalRead(1); //returns HIGH or LOW (true or false / 1 or 0)
}
Analog Read:
int sensorValue = 0;
void setup() {
// The analog pins are referenced by their analog port number, not their pin number and are as follows:
pinMode(1, INPUT); //THIS IS P2, P2 is Analog Input 1, so when you are using analog read you refer to it as 1
//pinMode(2, INPUT); //THIS IS P4, P2 is Analog Input 2, so when you are using analog read you refer to it as 2
//pinMode(3, INPUT); //THIS IS P3, P3 is Analog Input 3, so when you are using analog read you refer to it as 3
//pinMode(0, INPUT); //THIS IS P5, P5 is Analog Input 0, so when you are using analog read you refer to it as 0
}
void loop() {
sensorValue = analogRead(1); //read P2
//sensorValue = analogRead(2); //read P4
//sensorValue = analogRead(3); //read P3
//sensorValue = analogRead(0); //read P5
}