I would like to start off by giving all credit for any code or schematics to the original authors and if I don't quote the authors I deeply apologize, it is purely accidental.
I'm new to Arduino, but I've had courses in micro controllers specifically the pic16 and intro to C++ programming. I'm experienced in soldering and working with my hands.
I have a Arduino Uno R3 and I've gone through all the examples in 1. Basics. I'm trying to make a program that takes a int from 0 to 256 converts it to a binary string then outputs it to LED bar. The code I have converts and increments the number into binary which can be seen in serial output, but does not output to the LED bar.
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 0;
int pin8 = 0;
int pinx = 0;
byte i=0;
String binary;void setup()
{
Serial.begin(9600);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
}void loop()
{
binary=dectobin(i);
Serial.println(binary);
delay(500);for(int j=0; j<=7; j++)
{
if(binary[j]==1)
{
pinx=j;
digitalWrite(pinx, HIGH);
delay(1000);
}
else
{
pinx=j;
digitalWrite(pinx, LOW);
delay(1000);
}
}++i;
}
String dectobin(int decNum )
{
String result;
int zeros = 8 - String(decNum,BIN).length();
String myStr;
for (int i=0; i<zeros; i++)
{
myStr = myStr + "0";
}
myStr = myStr + String(decNum,BIN);
return myStr;
}