Skip to content

Commit ce0b801

Browse files
author
kobi
committed
fix var to uint in examples
1 parent ef126b6 commit ce0b801

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

examples/full/full.ino

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
Modbus slave(SLAVE_ID, CTRL_PIN);
4545

4646
void setup() {
47-
var pinIndex;
48-
var eepromValue;
47+
uint16_t pinIndex;
48+
uint16_t eepromValue;
4949

5050
/* set pins for mode.
5151
*/
5252
for (pinIndex = 3; pinIndex < 14; pinIndex++) {
5353
// get one 16bit register from eeprom
54-
eepromValue = EEPROM.get(pinIndex * 2);
54+
EEPROM.get(pinIndex * 2, eepromValue);
5555

5656
// use the register value to set pin mode.
5757
switch (eepromValue) {
@@ -175,29 +175,28 @@ void writeDigitlOut(uint8_t fc, uint16_t address, uint16_t status) {
175175
*/
176176
void writeMemory(uint8_t fc, uint16_t address, uint16_t length) {
177177
uint16_t value;
178-
uint16_t pinIndex;
178+
uint16_t registerIndex;
179179

180180
// write to eeprom.
181181
for (int i = 0; i < length; i++) {
182+
registerIndex = address + i;
183+
182184
// get uint16_t value from the request buffer.
183185
value = slave.readRegisterFromBuffer(i);
184186

185-
EEPROM.put((address + i) * 2, value);
187+
EEPROM.put(registerIndex * 2, value);
186188

187189
/* if this register sets digital pins mode,
188190
* set the digital pins mode.
189191
*/
190-
if ((address + i) < 14) {
191-
// get pin index.
192-
pinIndex = address + i;
193-
192+
if (registerIndex < 14) {
194193
// use the register value to set pin mode.
195194
switch (value) {
196195
case PIN_MODE_INPUT:
197-
pinMode(pinIndex, INPUT);
196+
pinMode(registerIndex, INPUT);
198197
break;
199198
case PIN_MODE_OUTPUT:
200-
pinMode(pinIndex, OUTPUT);
199+
pinMode(registerIndex, OUTPUT);
201200
break;
202201
}
203202
}

0 commit comments

Comments
 (0)