Skip to main content
explain switch decode
Source Link

On ATmega640/ATmega1280/ATmega1281/ATmega2560/ATmega2561 devices (with Arduino Mega using an ATmega640 or 2560), the analog input pins have their analog capabilities in addition to standard digital capabilities. They can be used to read or write digital values, like other digital pins on the device.

On ATmega48A/PA/88A/PA/168A/PA/328/P devices (with Arduino Uno using an ATmega168- or 328-family device) analog inputs A0 ... A5 have standard digital capabilities, but A6 and A7 do not. A6 and A7 on an Uno or Nano is limited to analog input. However, you can use a circuit like the following to multiplex several buttons. With this circuit attached to A6, you would get 1 V at A6 when you press S1; 2 V when you press S2; 3 V when you press S3; and so forth. You get 0 V at A6 when all the switches are open. One ladder circuit with 5 switches and 9 resistors

One would first use a fast analog read (about 13 μs) to decide if any switch is pressedpressed; for example, then either a fast or an ordinary analog read if the first reading is above 1/2 V. In some systems, a fast reading may be good enough by itself to decode switch number; if not, take a second reading via ordinary analog read. In any case, given an analog reading ar, and letting CPS be the expected step in counts from one switch to the next (sayin this case either 256/5 or 1024/5 depending upon use of 8 or 10 bits of readings), compute switch number via something like s = (ar+CPS/2)/CPS;.5 V

ladder circuit with 5 switches and 9 resistors

On ATmega640/ATmega1280/ATmega1281/ATmega2560/ATmega2561 devices (with Arduino Mega using an ATmega640 or 2560), the analog input pins have their analog capabilities in addition to standard digital capabilities. They can be used to read or write digital values, like other digital pins on the device.

On ATmega48A/PA/88A/PA/168A/PA/328/P devices (with Arduino Uno using an ATmega168- or 328-family device) analog inputs A0 ... A5 have standard digital capabilities, but A6 and A7 do not. A6 and A7 on an Uno or Nano is limited to analog input. However, you can use a circuit like the following to multiplex several buttons. With this circuit attached to A6, you would get 1 V at A6 when you press S1; 2 V when you press S2; 3 V when you press S3; and so forth. You get 0 V at A6 when all the switches are open. One would first use a fast analog read (about 13 μs) to decide if any switch is pressed, then either a fast or an ordinary analog read if the first reading is above (say) .5 V

ladder circuit with 5 switches and 9 resistors

On ATmega640/ATmega1280/ATmega1281/ATmega2560/ATmega2561 devices (with Arduino Mega using an ATmega640 or 2560), the analog input pins have their analog capabilities in addition to standard digital capabilities. They can be used to read or write digital values, like other digital pins on the device.

On ATmega48A/PA/88A/PA/168A/PA/328/P devices (with Arduino Uno using an ATmega168- or 328-family device) analog inputs A0 ... A5 have standard digital capabilities, but A6 and A7 do not. A6 and A7 on an Uno or Nano is limited to analog input. However, you can use a circuit like the following to multiplex several buttons. With this circuit attached to A6, you would get 1 V at A6 when you press S1; 2 V when you press S2; 3 V when you press S3; and so forth. You get 0 V at A6 when all the switches are open. ladder circuit with 5 switches and 9 resistors

One would first use a fast analog read (about 13 μs) to decide if any switch is pressed; for example, if the first reading is above 1/2 V. In some systems, a fast reading may be good enough by itself to decode switch number; if not, take a second reading via ordinary analog read. In any case, given an analog reading ar, and letting CPS be the expected step in counts from one switch to the next (in this case either 256/5 or 1024/5 depending upon use of 8 or 10 bits of readings), compute switch number via something like s = (ar+CPS/2)/CPS;.

Source Link

On ATmega640/ATmega1280/ATmega1281/ATmega2560/ATmega2561 devices (with Arduino Mega using an ATmega640 or 2560), the analog input pins have their analog capabilities in addition to standard digital capabilities. They can be used to read or write digital values, like other digital pins on the device.

On ATmega48A/PA/88A/PA/168A/PA/328/P devices (with Arduino Uno using an ATmega168- or 328-family device) analog inputs A0 ... A5 have standard digital capabilities, but A6 and A7 do not. A6 and A7 on an Uno or Nano is limited to analog input. However, you can use a circuit like the following to multiplex several buttons. With this circuit attached to A6, you would get 1 V at A6 when you press S1; 2 V when you press S2; 3 V when you press S3; and so forth. You get 0 V at A6 when all the switches are open. One would first use a fast analog read (about 13 μs) to decide if any switch is pressed, then either a fast or an ordinary analog read if the first reading is above (say) .5 V

ladder circuit with 5 switches and 9 resistors