Notes Arduino Nano
Notes Arduino Nano
Notes Arduino Nano
USB Driver
Arduino Nano needs a different USB driver for Windows 7
➔ Com6
First Test
Arduino Blink Sketch
Pinout Diagram
see https://forum.arduino.cc/index.php?topic=147582.0
boards.txt
Path: Arduino/hardware/Arduino/avr/boards.txt
boards.txt describes the features of the available boards in the IDE, the size of the eeprom and the
the bootloader to be used.
boards.txt:
…
nano.menu.cpu.atrmega328=ATmega328
…
nano.build.core=Arduino
nano.build.variant=eightanaloginputs
pin_arduino.h:
#include “../standards/pins_arduino.h”
{Arduino}/hardware/arduino/avr/variants/stanards/pin_arduino.h:
byte characters[] = {
// 0,a,b,c,d,e,f,g
B01111110, // 0
B00110000, // 1
B01101101, // 2
B01111001, // 3
B00110011, // 4
B01011011, // 5
B01011111, // 6
B01110000, // 7
B01111111, // 8
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(PD2, OUTPUT);
pinMode(PD3, OUTPUT);
pinMode(PD4, OUTPUT);
pinMode(PD5, OUTPUT);
pinMode(PD6, OUTPUT);
pinMode(PD7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // decimal point
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (segment == ONES) {
digitalWrite(9, LOW);
digitalWrite(ONES, HIGH);
digitalWrite(TENS, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(ONES, LOW);
digitalWrite(TENS, HIGH);
}
}
#define ONES 10
#define TENS 11
byte characters[] = {
// 0,a,b,c,d,e,f,g
B01111110, // 0
B00110000, // 1
B01101101, // 2
B01111001, // 3
B00110011, // 4
B01011011, // 5
B01011111, // 6
B01110000, // 7
B01111111, // 8
B01111011 // 9
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(PD2, OUTPUT);
pinMode(PD3, OUTPUT);
pinMode(PD4, OUTPUT);
pinMode(PD5, OUTPUT);
pinMode(PD6, OUTPUT);
pinMode(PD7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // decimal point
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
void refreshDisplay(){
if (refreshcounter++ % 2 == 0) {
writeDigit(tens, TENS);
} else {
writeDigit(ones, ONES);
}
}
if (segment == ONES) {
digitalWrite(9, LOW);
digitalWrite(ONES, HIGH);
digitalWrite(TENS, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(ONES, LOW);
digitalWrite(TENS, HIGH);
}
}
By using a capacitor it is possible to build a low pass filter that reduce the bouncing effect and
eliminates the very small spikes. If you ever have like to use this solution put the capacitor as near as
possible to the contacts. 100nF will do here.
Another solution is to detect changes of the signal in a very small timeframe and ignore them. You
can find a solution using this approach on the Arduino playground article.
The solution I found in some of the libraries around is to exactly follow all the 4 possible states of the
signals that a switch will pass when being turned from one position to the next and detect the next
position only when reaching a detent state. Even when a bouncing will occur it will not change the
position counting more than once.
Sketch
/*
* 7-segment LED display with rotary encoder
*
* M. July 2017
*/
#include <MsTimer2.h>
#define ONES 10
#define TENS 11
#define ROTARY_SWITCH 14
#define ROTARY_A 15
#define ROTARY_B 16
enum programMode {
count,
set_counter
};
byte characters[] = {
// 0,a,b,c,d,e,f,g
B01111110, // 0
B00110000, // 1
B01101101, // 2
B01111001, // 3
B00110011, // 4
B01011011, // 5
B01011111, // 6
B01110000, // 7
B01111111, // 8
B01111011 // 9
};
void refreshDisplay();
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(PD2, OUTPUT);
pinMode(PD3, OUTPUT);
pinMode(PD4, OUTPUT);
pinMode(PD5, OUTPUT);
pinMode(PD6, OUTPUT);
pinMode(PD7, OUTPUT);
//rotary encoder
pinMode(ROTARY_SWITCH, INPUT_PULLUP); // switch
pinMode(ROTARY_A, INPUT_PULLUP); // Encoder A
pinMode(ROTARY_B, INPUT_PULLUP); // Encoder B
currentTime = millis();
loopTime = currentTime;
}
void loop() {
void refreshDisplay(){
int tens = number / 10;
int ones = number % 10;
if (refreshcounter++ % 2 == 0) {
writeDigit(tens, TENS);
} else {
writeDigit(ones, ONES);
}
readSwitch();
if (mode == set_counter) {
readRotaryEncoder();
}
void readRotaryEncoder() {
void readSwitch() {
void toggleMode() {
if (mode == count) {
mode = set_counter;
} else {
mode = count;
}
}
if (segment == ONES) {
digitalWrite(9, LOW);
digitalWrite(ONES, HIGH);
digitalWrite(TENS, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(ONES, LOW);
digitalWrite(TENS, HIGH);
}
}