Hi I am new to programming,
I am trying to create bytes, but i keep getting 28(11100) when im expecting 170(10101010). I suspect it is because I did not add 0b eg. 0b10101010 but it wont allow me to place 0b in front of the equation.
code:-
void loop()
int bit1 = 1;
int bit2 = 0;
int bit3 = 1;
int bit4 = 0;
int bit5 = 1;
int bit6 = 0;
int bit7 = 1;
int bit8 = 0;
byte b;
b = (bit12^7)+(bit22^6)+(bit32^5)+(bit42^4)+(bit52^3)+(bit62^2)+(bit72^1)+(bit82^0);
//equals 170 if 10101010
Serial.println(b, BIN);
Thank you AWOL its working now
i changed the LBS to bit0, my next plan is to use a Xbox 360 controller with USB host to control an arduino rc car.
I want to use 'hand shake' protocol so the arduino knows the RC car has received the message. The only way i could think of to do such is transmit the exact same message back to arduino no.1 . what do you think about this?
Onmt39:
I want to use 'hand shake' protocol so the arduino knows the RC car has received the message. The only way i could think of to do such is transmit the exact same message back to arduino no.1 . what do you think about this?
Or you could just check-sum the message and send the checksum back, depending on how long/complex the transmission processes are.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
byte bits[] = {0, 1, 0, 1, 0, 1, 0, 1};
byte b = 0;
for (byte i = 0; i < 8; i++)
{
bitWrite(b, i, bits[i]);
}
Serial.print(b);
Serial.print(" ");
Serial.println (b, BIN);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
byte bits[] = {1,0,1,0,1,0,1,0};
byte b = 0;byte j = 0;
for (byte i = 7; i < 8; i--)
{
bitWrite(b, i, bits[j]);j++;
}
Serial.print(b);
Serial.print(" ");
Serial.println (b, BIN);
}
I only showed the other because that's what i already had for something else