Go Down

Topic: Need help coding a nerf ammo counter (Read 2058 times) previous topic - next topic


I don't really have any programming experience. And I will try that tutorial. It's just that I'm away for the weekend without my computer and that's where my code and components are.


Mar 01, 2014, 10:52 am Last Edit: Mar 02, 2014, 07:06 am by leo72 Reason: 1
Here is the code I had.
Code: [Select]
int buttonPin = 6;
int count = 6;
int buttonState = 0;

void setup()
 DDRB = B11111111; // sets D13~D8 to output
 DDRD = B10000000; // sets D7 to output, D6~D0 to input

void loop()
 buttonState = digitalRead(buttonPin); // read D6

 if (buttonState == HIGH)
 // delay here for debouncing purposes
 if (count>= 6)
   PORTB = B11111111;

 if (count>= 5)
   PORTB = B11111110;
 if (count>= 4)
   PORTB = B11111100;
 if (count>= 3)
   PORTB = B11111000;
 if (count>= 2)
   PORTB = B11110000;
 if (count>= 1)
   PORTB = B11100000;
 if (count>= 0)
   PORTB = B11000000;


Code: [Select]

What happened to the code tags?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Sorry please excuse me. What are code tags?


What are code tags?

Read here, ยง #7:


Alright. See the code will upload with no errors I'm just not sure what in the code is wrong.  So I was hoping someone could either write me a new code or tell me where I went wrong.


I didn't follow the whole discussion but I've read your very first post and it seems to me that you're trying to light up some LEDs on a LED bar.

The code you posted make use of the direct manipulation of the Arduino logic ports. This means that instead of finding some digitalWrite(pin, status) instructions you find a single PORTB = xxxxx command.
This tells the microcontroller to immediately set all the pin of PORTB using the bits of that number.
PORTB is the port that drives the pins from PB0 to PB7. In the Arduino world, they are pins D8..D13 plus the 3 pins where usually the external clock is connected to.

Look at the image below:

So, if you're creating a standalone project, remember that:
1) you cannot use PB6 and PB7 pins unless you disconnect the crystal
2) to disconnect the crystal, you have to set the micro to work with the internal oscillator (1 or 8 MHz)
3) if you want to use the external crystal, you have to change the logic port (i.e. you could use PORTD)
4) you can try to change the sketch by using digitalWrite instructions instead


So are you saying I should change some of the pins around?


Mar 02, 2014, 08:47 am Last Edit: Mar 02, 2014, 08:49 am by TomGeorge Reason: 1
Hi, can you answer these questions numbered?

1) What arduino board are you using?

2) Did you try the link to the 7seg example.
did it work?

3) Can you supply us with a picture of you project so far.

4) Can you post a circuit diagram either CAD or picture of hand drawn, in jpg, gif or pdf.

We need to know this much about your project, BECAUSE you started it, which means you are way ahead of us, we need to catch up and they don't sell crystal balls on ebay.

Tom........We are here to help.... :) Please we need all these questions answered.
Everything runs on smoke, let the smoke out, it stops running....


Hi I made a nerf dart counter check it out and let me know what you think!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131