Data Streamer Button Press Count over 255

Gstue

New Member
Joined
Mar 24, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,
I'm trying to do a count of button presses using a Metro Mini and Data Streamer but it only seems to go to 255 and start at zero again. If I use less then 255 it works fine and starts at 1. I'm trying to reach a count up to around 31000 cycles if the material lasts that long. I've tried to use a cell state change to do this but it does not register the stream only manual inputs with Carriage Return. Also tried to do multiple counts of cells when it sees a number come up then go to another cell and add the cells but it doesn't lock that number in the cell when reached. I'm very new at this and I've combined code from different sources then comment out the items that doesn't work. I can start and stop the motor using excel macros or a given number to go to less then 255. The code below is for the Metro Mini (Arduino). I would like to either use this or a VBA code or a formula to do a count of cycles. Sorry about the mess in the code, still experimenting/learning
//LM2 working
#include <AlwaysOffButton.h>
#include <AlwaysOnButton.h>
#include <ButtonBase.h>
#include <ButtonEnums.h>
#include <CountingButton.h>
#include <CycleButton.h>
#include <LatchingButton.h>
#include <MomentaryButton.h>
#include <PushEventButton.h>
#include <ResettableButton.h>
#include <TwoStateButton.h>

/*
This example demonstrates how the PushEventButton captures each individual
button press as discrete events. It does not matter how long the button is
pressed down or released. Only the transition between pressed and released
is captured.

The button should be wired such that when pressed, the "buttonPin" is
connected to ground.

The LED should be wired with the "ledPin" to the positive lead and the
negative lead should be connected to ground. A current limiting resistor
should be used.
*/
const int len = 60;
char my_str[len];
char pos = 0;

int incomingByte = 0; // for incoming serial data

#include "PushEventButton.h"

// Change these if your button or LED are on other pins.
int buttonPin = 2; // Pin2 Rotary sensor
int ledPin = 13; // Pin 13
byte buttonPresses=0; // how many times button has been pressed
byte lastPressCount=0; // to keep track of last press count

// The button will automatically configure the button pin.
// Because the "CAPTUREPUSH" option is used, the event is only as soon as
// the button is pressed down.
PushEventButton button(buttonPin,PushEventButton::CAPTUREPUSH);

void setup()
{
// Setup the output LED.
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600); // Serial Communication
pinMode(11,OUTPUT); // sets the digital pin 11 (LED PIN) as output
//pinMode(buttonPin, INPUT);
}
void loop()
{
// This will return true only once for each button push.
// This example is triggered on the press of the button. As soon as the button is pressed down
// this returns true. It does not matter how long the button is held down, the light flashes
// for the same amount of time. Nothing happens on the button release.
// int buttonState=digitalRead(buttonPin);
bool buttonPushed = button.pushed();

// Set the LED to the state of the button press.
digitalWrite(ledPin, buttonPushed);

if (buttonPushed)
{
// If the button was pushed, the light will be turned on. We need a brief delay to make sure the
// on state of the LED is long enough to be seen.
delay(100);
buttonPresses++;
if (buttonPresses==501) buttonPresses = 1; // count rollover
if (lastPressCount!= buttonPresses) // only do output if the count has changed

Serial.print (""); // out to serial
Serial.println(buttonPresses, DEC);

}

lastPressCount=buttonPresses; // track last press count

}

void serialEvent() {
//statements
outputStuff();
}
void outputStuff(){
// send data only when you receive data:
if (Serial.available()>0) {
// read the incoming byte:
incomingByte = Serial.read();

my_str[pos] = incomingByte;
pos++;

if(incomingByte==10){ //10 is line feed character
pos = 0;

//Turn on pin 11 LED if first received character is the letter "t"
if (my_str[0] == 't'){
// Serial.print("t,HIGH,");

digitalWrite(11,LOW);
} else {
digitalWrite(11,HIGH);
// Serial.print("not t,LOW,");
}
// Serial.print(my_str);
//clear the string for next time
for (int i = 0; i<=len-1; i++){
my_str = 0;

}
}
}
}
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Well that was easy! Told you I was new at it. Seems to work up to 525 so far. Thank you Very much!!!
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top