i'am making a sensor circuit using arduino ic standaloe and i need all the 19 pins
i need pin 0,1 and 2 to be configured as input
in the sketch i set them as input but they are not working proberly
here is my code
#include <TimerOne.h>
#define output_v A0 //vn
#define output_i A1 //in
#define bus_voltage A2 //vb
#define load_current A3 //il
#define load_current_2 A4
#define converter_current A5
#define sel1 0
#define sel2 1
#define sel3 2
#define p0 3
#define p1 4
#define p2 5
#define p3 6
#define p4 7
#define p5 8
#define p6 9
#define p7 10
#define p8 11
#define p9 12
bool s1=false,s2=false, s3=false;
int num;
// Speed up analogRead
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
int time_delay=12;
int vn;
void read_output_voltage()
{
vn=analogRead(output_v);
delayMicroseconds(time_delay);
}
int vb;
void read_bus_voltage()
{
vb=analogRead(bus_voltage);
delayMicroseconds(time_delay);
}
int in;
void read_output_current()
{
in=analogRead(output_i);
delayMicroseconds(time_delay);
}
int il;
void read_load_current()
{
il=analogRead(load_current);
delayMicroseconds(time_delay);
}
bool num_bit[10];
void show()
{
for(int i=9;i>=0;i--)
{
num_bit[i]=num%2;
num/=2;
}
for(int i=p0;i<=p9;i++)
{
digitalWrite(i,num_bit[i-p0]);
//Serial.print(num_bit[i-2]);
}
}
void setup() {
for(int x=3;x<13;x++)
pinMode(x,OUTPUT);
pinMode(sel1,INPUT);
pinMode(sel2,INPUT);
pinMode(sel3,INPUT);
//Serial.begin(57600);
//faster analogRead(); // set prescale to 16
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
Timer1.initialize(50);
Timer1.attachInterrupt(control_pins);
}
void loop() {
read_output_voltage();
read_output_current();
read_bus_voltage();
read_load_current();
//print_status();
//Serial.println();
}
void control_pins(void)
{
s1=digitalRead(sel1);
s2=digitalRead(sel2);
S3=0;
//s3=digitalRead(sel3);
if(s1==0 && s2==0){num=vn;}
else if(s1==0 && s2==1){num=in;}
else if(s1==1 && s2==0){num=vb;}
else if(s1==1 && s2==1){num=il;}
show();
}