Dear all
I have 8 digital Ios. i wanted to read status of 8 digital io as bits and move the value to buffer of character 8 bits which hold status of 8 digital Io. can some one guide me how it can be done
Currently i am
unsigned char ser_data[10];
ser_data[1]=0X0A;
That means it hold the value of 8 digital Io in 0000 1010 format. How can move realistic value of digitalIO ino ser_data[1] by eliminating 0X0A line
How are the I/O pins aligned, next to each other, same port, scattered?
How do you want the bit data stored? bit0 = I/O pin0, bit1 = I/O pin1, etc, or what?
You can use masks, bit shifts, or bit-fields in a struct just to name three methods.
More info from you.
Lena
October 22, 2018, 7:12am
3
Take a look at << and | Operators - i'm shure you'll find the answer for yourself.
Greets Lena
How can i move the value to ser_data[1] and print Serially
unsigned char ser_data[10];
#define LED D1
#define LED1 D0
#define LED2 D2
#define LED3 D3
#define LED4 D4
#define LED5 D5
#define LED6 D6
#define LED7 D7
typedef union
{
struct
{
unsigned INF1: 1;
unsigned INF2: 1;
unsigned INF3: 1;
unsigned INF4: 1;
unsigned INF5: 1;
unsigned INF6: 1;
unsigned INF7: 1;
unsigned INF8: 1;
};
unsigned char INF1_9;
} INPUT_TYPE;
INPUT_TYPE INPUT_T;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(D0, INPUT);
pinMode(D1, INPUT);
pinMode(D2, INPUT);
pinMode(D3, INPUT);
pinMode(D4, INPUT);
pinMode(D5, INPUT);
pinMode(D6, INPUT);
pinMode(D7, INPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(D0) == 1)
{
INPUT_T.INF1 = 1;
} else
{
INPUT_T.INF1 = 0;
}
if (digitalRead(D1) == 1)
{
INPUT_T.INF2 = 1;
Serial.println("Pin high");
} else
{
INPUT_T.INF2 = 0;
Serial.println("Pin LOW");
}
if (digitalRead(D2) == 1)
{
INPUT_T.INF3 = 1;
} else
{
INPUT_T.INF3 = 0;
}
if (digitalRead(D3) == 1)
{
INPUT_T.INF4 = 1;
Serial.println("Pin high");
} else
{
INPUT_T.INF4 = 0;
Serial.println("Pin LOW");
}
if (digitalRead(D5) == 1)
{
INPUT_T.INF5 = 1;
} else
{
INPUT_T.INF5 = 0;
}
if (digitalRead(D6) == 1)
{
INPUT_T.INF6 = 1;
Serial.println("Pin high");
} else
{
INPUT_T.INF6 = 0;
Serial.println("Pin LOW");
}
if (digitalRead(D7) == 1)
{
INPUT_T.INF7 = 1;
} else
{
INPUT_T.INF7 = 0;
}
delay(1000);
}