Hello!
I use an Arduino nano and I want a 5 led output in binary with an input from the serial monitor. The numbers I want to output range from -16 to 15 in a two-complement binary-system. I started with this code. I dont think I need to show the circuit it is just 5 leds with resistors connected to the arduino nano.
int number = 0;
char bitvalue = 0;
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6; // MSB
void setup() {
Serial.begin(9600);
Serial.println("ready: ");
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
}
void loop() {
bitvalue = bitRead(number,0);
digitalWrite(2, bitvalue);
digitalWrite(3, bitvalue);
digitalWrite(4, bitvalue);
digitalWrite(5, bitvalue);
digitalWrite(6, bitvalue);
}
You only followed half the advice. Go back and read the code handout that you were given. Also, it's more productive if you tell us what results you observed instead of asking what was intended...
No. That is going to always turn off Pin 2 (0 == LOW) and always turn on Pins 3 through 6 (non-0 == HIGH). I showed you how to set the first two pins... I thought you could take it from there.