Introduction
Arduino Uno has up to six analog input pins. Each analog inputs has resolution of 10-bit (0 – 1023). By default its reference voltage is 5V.
Within this example, we use analog reading on A0 and show its voltage level on seven segment display.
Schematic Diagram |
Arduino Programming
Arduino analogRead() function perform an analog voltage reading on any analog pin ranges from A0 to A5. Here we use A0 pin to read input voltage. We use a DIY Arduino shield for this example.
/* Main.ino file generated by New Project wizard
*
* Created: Tue Dec 4 2018
* Processor: Arduino Uno
* Compiler: Arduino AVR
*/
#define POT A0
#define BUZ 6
char ssd[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int cnt=0;
void displays(char cnt){
digitalWrite(7,bitRead(ssd[cnt],0));
digitalWrite(8,bitRead(ssd[cnt],1));
digitalWrite(9,bitRead(ssd[cnt],2));
digitalWrite(10,bitRead(ssd[cnt],3));
digitalWrite(11,bitRead(ssd[cnt],4));
digitalWrite(12,bitRead(ssd[cnt],6));
digitalWrite(13,bitRead(ssd[cnt],5));
}
void setup()
{ // put your setup code here, to run once:
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(BUZ,OUTPUT);
}
void loop()
{ // put your main code here, to run repeatedly:
int readA0=analogRead(POT);
delay(100);
cnt=(float)readA0*5.0/1023;
if(cnt>3) digitalWrite(BUZ,HIGH);
else digitalWrite(BUZ,LOW);
displays(cnt);
}
Click here to download this example package.
No comments:
Post a Comment