Using parseInt to call funcation

Two arduino megas linked with HC12, 1st arduino sends 1-4 depending on which button is pressed to the second unit and there I am trying to use parseInt to call a function.. From what I can find online this should work but I am super new so could be something simple I just cant see... Code is below... Thanks!

void loop() {
   Serial1.begin (9600); 
   while (Serial1.available()) {
   }

    {
      LedStat = Serial1.parseInt();
      Serial.write(LedStat);
      
    if (LedStat==1) longPressStart1;
    if (LedStat==2) longPressStart2;
  }
   

Post the entire program, not just loop().

How is the behavior different from what you expect?

It isnt calling the function at all, I have checked the link and I am receiving the information but its like the parseInt isnt reading the value is why I was thinking I coded it wrong..

#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>   // Hardware-specific library
MCUFRIEND_kbv tft;
#include "OneButton.h"
#include <FreeDefaultFonts.h>
#include <FastLED.h>
#include <SoftwareSerial.h>
#define NUM_LEDS 30
#define DATA_PIN 27
CRGB leds[NUM_LEDS];
int LedStat;
int LedStat2;
//Display colors
#define BLACK   0x0000
#define RED     0xF800
#define GREEN   0x07E0
#define WHITE   0xFFFF
#define GREY    0x8410
const unsigned int MAX_MESSAGE_LENGTH = 12;
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

int dataNumber = 0;             // new for this version




void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
Serial1.begin (9600);
Serial.println("Starting project");
  
    //Display settings
    uint16_t ID = tft.readID();
    if (ID == 0xD3D3) ID = 0x9481; //force ID if write-only display
    tft.begin(ID);
    tft.setRotation(1);
    tft.setTextSize(5);
    tft.print("Starting");
    //Led setup
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
    //digitalWrite(32, HIGH); //HC-12 Power
    //digitalWrite(33, LOW); //HC-12 Ground
}

void loop() {
   Serial1.begin (9600); 
   while (Serial1.available()) {
   }

    {
      LedStat = Serial1.parseInt();
      Serial.write(LedStat);
      
    if (LedStat==1) longPressStart1;
    if (LedStat==2) longPressStart2;
  }
   



  }
  






// This function will be called once, when the button1 is pressed for a long time.
void longPressStart1() {
  Serial.println("Button 1");
  tft.fillScreen(BLACK);
  tft.setTextColor(RED, GREY);
  tft.setTextSize(5);
  tft.setCursor(50, 120);
  tft.print("Button 1 longpress");
  fill_solid (leds, NUM_LEDS, CRGB(255, 0, 0));
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  fill_solid (leds, NUM_LEDS, CRGB (0, 0, 0));
  FastLED.show();
  delay(500);

  LedStat = 1;

  LongPressBlink1();
}`Preformatted text`

When calling a function, you need the parens even if not passing any data, or it won't work correctly.
if (LedStat==2) longPressStart2();

That was it!! Thank you! :slight_smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.