Hi! i’m new to the arduino and i’ve bought several components to start learning how it works. i’ve written a small program to count from 0 to 1023, and display the number as a binary value on a 1x10 LED array.
short description of the hardware setup, i’ve done it all on a protoshield. the LED array is connected with the anodes to pins 4 through 13. and the cathodes are connected via one shared resistor to the ground. one potentiometer is connected to the analog pin 0, and 5v and ground of course.
I’ve posted a video on youtube, but since this is my first post here i’m not allowed to post the link yet.
If you watched the video, then you’d see the arduino doesn’t quite do what I want. it works for the first 4 bits perfectly, but skips the 5th, and the 6th behaves oddly.
here’s the code for it.
#include <math.h>
int pin[10],pot = 0;
int val = 0;
void setup(){
for(int i = 0;i < 10; i++){
pin[i] = 4+i;
pinMode(pin[i], OUTPUT);
}
}
int n = 0;
void loop(){
val = analogRead(pot);
if(n & 0x0001)
digitalWrite(pin[9],HIGH);
else
digitalWrite(pin[9],LOW);
if(n & 0x0002)
digitalWrite(pin[8],HIGH);
else
digitalWrite(pin[8],LOW);
if(n & 0x0004)
digitalWrite(pin[7],HIGH);
else
digitalWrite(pin[7],LOW);
if(n & 0x0008)
digitalWrite(pin[6],HIGH);
else
digitalWrite(pin[6],LOW);
if(n & 0x0010)
digitalWrite(pin[5],HIGH);
else
digitalWrite(pin[5],LOW);
if(n & 0x0020)
digitalWrite(pin[4],HIGH);
else
digitalWrite(pin[4],LOW);
if(n & 0x0040)
digitalWrite(pin[3],HIGH);
else
digitalWrite(pin[3],LOW);
if(n & 0x0080)
digitalWrite(pin[2],HIGH);
else
digitalWrite(pin[2],LOW);
if(n & 0x0100)
digitalWrite(pin[1],HIGH);
else
digitalWrite(pin[1],LOW);
if(n & 0x0200)
digitalWrite(pin[0],HIGH);
else
digitalWrite(pin[0],LOW);
delay(val);
n = (n+1) % 1024;
}
please help with this, i’ve obviously made some errors in the code, or my arduino’s broken, most likely it’s my code that’s busted.