Skip to content

Commit

Permalink
Fixed the issue of analog pin parsing error on control boards using f…
Browse files Browse the repository at this point in the history
…irmata protocol.
  • Loading branch information
zhengyangliu committed Jun 20, 2024
1 parent 047cd13 commit 11c5231
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/devices/arduinoEsp8266/arduinoEsp8266.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ class OpenBlockArduinoEsp8266Device {

// Create a new Arduino esp8266 peripheral instance
this._peripheral = new ArduinoEsp8266(this.runtime, this.DEVICE_ID, originalDeviceId);

this._peripheral.numDigitalPins = 17;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/devices/arduinoLeonardo/arduinoLeonardo.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ class OpenBlockArduinoLeonardoDevice {

// Create a new Arduino leonardo peripheral instance
this._peripheral = new ArduinoLeonardo(this.runtime, this.DEVICE_ID, originalDeviceId);

this._peripheral.numDigitalPins = 14;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/devices/arduinoMega2560/arduinoMega2560.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ class OpenBlockArduinoMega2560Device {

// Create a new Arduino mega 2560 peripheral instance
this._peripheral = new ArduinoMega2560(this.runtime, this.DEVICE_ID, originalDeviceId);

this._peripheral.numDigitalPins = 54;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/devices/arduinoUno/arduinoUno.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ class OpenBlockArduinoUnoDevice {

// Create a new Arduino uno peripheral instance
this._peripheral = new ArduinoUno(this.runtime, this.DEVICE_ID, originalDeviceId);

this._peripheral.numDigitalPins = 14;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/devices/common/arduino-peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class ArduinoPeripheral{
*/
parsePin (pin) {
if (pin.charAt(0) === 'A') {
return parseInt(pin.slice(1), 10) + 14;
return parseInt(pin.slice(1), 10) + this.numDigitalPins;
}
return parseInt(pin, 10);
}
Expand Down Expand Up @@ -538,7 +538,7 @@ class ArduinoPeripheral{
if (this.isReady()) {
pin = this.parsePin(pin);
// Shifting to analog pin number.
pin = pin - 14;
pin = pin - this.numDigitalPins;
this._firmata.pinMode(pin, this._firmata.MODES.ANALOG);
return new Promise(resolve => {
this._firmata.analogRead(pin, value => {
Expand Down

0 comments on commit 11c5231

Please sign in to comment.