Hi guys,
I am currently new to Arduino. I would like to transmit binary data from one digital pin to another and then reprint it with the help from interrupt. However when i run my code the output is "010".
#define TX_PIN 9
#define RX_PIN 3
uint8_t data = B01101001;
void isrhandler(){
int pinState = digitalRead(RX_PIN);
if(pinState == HIGH){
Serial.print("1");
}
else{
Serial.print("0");
}
}
void sendSignal(String string){
for(int i=0;i<8;i++){
if(string[i]==0){
digitalWrite(TX_PIN, LOW);
}
else{
digitalWrite(TX_PIN, HIGH);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(RX_PIN, INPUT_PULLUP);
pinMode(TX_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(RX_PIN), isrhandler, CHANGE);
String string = String(data, BIN);
sendSignal(string);
}
void loop() {
// put your main code here, to run repeatedly:
}