Help with arduino c++ code to count pulses

closed account (jEb91hU5)
Hello, I'm requesting help to design and implement an Arduino C/C++ program to count each LOW to HIGH transition occurring in a train of pulses (generated by a NE555 timer). When each transition occurs, the count will be displayed in the bank of 8 LEDs (in a row on the breadboard all connected to digital pins on the Arduino Mega 2560). All the wiring is correct, it's just the code I need some help with. I haven't coded much in many years and I've never been the best at it, though I do need it to finish this small project. I know it shouldn't be very hard to do. Any help is appreciated.

Extra info:
1. By setting up GPIO pin #2 as an input pin, you can read the logic state (HIGH or LOW) of the pulse train
generated by the NE555 timer circuit.

2. Using a polling loop, detect when a LOW to HIGH transition takes place and, when it does, increment an 8-bit
counter. The counter is not to be incremented any other time. As transitions are counted, it’s okay for the
counter MSB (Most Significant Bit) to carry out into the “bit bucket” and the count start over at zero again.

3. Whenever the counter is incremented, the 8-bit count should be displayed in the group of 8 LEDs on your utility
breadboard.

So, when started, the binary value displayed in the LED bank should increment every time a LOW to HIGH transition
occurs. (The rightmost LED displays the counter LSB and the leftmost LED displays the counter MSB.) Since the
transitions occur approximately once every two seconds, the value displayed in the LEDs should increment
approximately every two seconds.

I can give more information if I can. From my code, you'll see I haven't done too much yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <CSCI_LED.h>
#include <CSCI_GPIO.h>
#include <CSCI_Pushbutton.h>
#include <CSCI_Console.h>
#include <CSCI_SysUtils.h>

const uint8_t *PortDirPtr = &DDRL;
const uint8_t *PortDataPtr = &PORTL;

const int LedOnState = LOW;
const int LedOffState = HIGH;

// GPIO input pin no 2
const int PulsePin = 2

// GPIO input pin for pushbutton "A"
const int PinButtonA = 52;

// LED pin numbers on arduino mega 2560

const int BitToPin[8] = { 49, 48, 47, 46, 45, 44, 43, 42 };

void setup() {
  

}

void loop() {
  

}
Last edited on
Your code doesn't appear to have much to do with an Arduino or the timer chip. In general terms, the Arduino is at best a sub-system of C++ and not a good way to learn C++. However, none of that means you should give up on either.

https://www.instructables.com/NE555-With-Arduino-Uno-R3/ might be useful. A counter (declared outside the loop) can be incremented each time a HIGH value is read in the loop. It's a simple addition to the demo.

It is also a good idea to output to the serial monitor to verify the counter/HIGH/LOW results rather than relying on the added complexity of an led/matrix display until you know the program is doing what you want.
Topic archived. No new replies allowed.