Stuck trying to enter a number

Hi All,

I am trying to enter a number to set a variable called pon. But i am getting an error when compiling this code. Could someone offer some help to a newbie please?

the error messages are also listed.

Error:-
C:\Users\ilpro\OneDrive\Documents\Arduino\HHO_Generator_v1.1\ponSet.ino: In function 'void ponSet()':
C:\Users\ilpro\OneDrive\Documents\Arduino\HHO_Generator_v1.1\ponSet.ino:26:29: error: conversion from 'int' to 'const String' is ambiguous
In file included from C:\Users\ilpro\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:232:0,
from C:\Users\ilpro\AppData\Local\Temp\arduino\sketches\8D0660CAF5BFD2E7DB31264677A2B787\sketch\HHO_Generator_v1.1.ino.cpp:1:
C:\Users\ilpro\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:61:2: note: candidate: String::String(const __FlashStringHelper*)
String(const __FlashStringHelper str);
^~~~~~
C:\Users\ilpro\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:61:2: note: conversion of argument 1 would be ill-formed:
C:\Users\ilpro\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/WString.h:59:2: note: candidate: String::String(const char
)
String(const char *cstr = "");
^~~~~~

Code :


```cpp
void ponSet() {
  ponFlag = 0;
  csr = 7;
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("Pulse On Time");
  lcd.setCursor(0, 1);
  lcd.print("On Time (uS) 1-");
  rem = 1000 - pon;
  lcd.print(rem);
  lcd.setCursor(0, 2);
  lcd.print("Pulse = ");
  do {
    char key = keypad.getKey();
    if (key) {
      lcd.setCursor((csr), 2);
      lcd.print(key);
      csr++;

      if (key >= '0' && key <= '9') {  // only act on numeric keys
        ponString += key;              // append new character to input string
      } else if (key == 'E') {
        if (ponString.length() > 0) {
          ponInt = ponString.toInt();  // YOU GOT AN INTEGER NUMBER
          ponString = "";              // clear input
          if (ponString > (rem)) {
            lcd.clear();
            lcd.setCursor(4, 1);
            lcd.print("Too High");
            delay(100);
            ponSet();
          }
          if (ponInt <= (rem)) {
            pon = ponInt;
            ponFlag = 1;
          }
        }
      } else if (key == 'C') {
        ponString = "";  // clear input
        ponFlag = 0;
        loop();
      }
    }
  } while (ponFlag == 0);
}

Welcome to the forum

Are you sure that you posted the whole sketch that produced the errors or maybe you didn't post the full list of errors. Copy them from the IDE using the button conveniently provide for the purpose

I as because I get a different set of errors starting with the face that the ponFlag variable was not declared in the code posted

Welcome and thanks for using code tags in your first post. Unfortunately your code is incomplete so we can't compile it ourselves.

Comparing a String (capital S) with an integer ?? There might be more wrong.

Sorry for any errors in posting, I am a bit new to all of this. I only included the bit where I got the error.

As far as my coding skills are concerned, I am still at the cut and paste level. So be gentle :rofl:


```cpp
#include <LiquidCrystal_I2C.h>

//HHO Pulse Generator
// Version 1.1
// Written by Phil Wainwright
// (c) Phil Wainwright 2024
// All Right Owned By North Yorkshire Prototype Development


#include <Keypad.h>

LiquidCrystal_I2C lcd(0x27, 20, 04);

//variables
int ponFlag = 0;
int pofFlag = 0;
int pon = 0;
int pof = 0;
String ponString;
long ponInt;
String pofString;
long pofInt;
int csr = 0;
int rem = 0;
int runFlag = 0;
unsigned long freq;
int freqNum;

//pins
int pulseOut = 2;
int LED = 13;


const byte ROWS = 5;  //four rows
const byte COLS = 4;  //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  { 'A', 'B', '#', '*' },
  { '1', '2', '3', 'U' },
  { '4', '5', '6', 'D' },
  { '7', '8', '9', 'C' },
  { 'L', '0', 'R', 'E' }
};
byte rowPins[ROWS] = { 22, 24, 26, 28, 30 };  //connect to the row pinouts of the keypad
byte colPins[COLS] = { 38, 36, 34, 32 };      //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  pinMode(pulseOut, OUTPUT);
  pinMode(LED, OUTPUT);
  digitalWrite(pulseOut, LOW);
  digitalWrite(LED, LOW);
  Serial.begin(115200);
  ponString.reserve (3);
  pofString. reserve (3);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(5, 1);
  lcd.print("HHO Pulse");
  lcd.setCursor(9, 2);
  lcd.print("By");
  lcd.setCursor(3, 3);
  lcd.print("P. Wainwright");

  delay(3500);
  lcd.clear();
}

void loop() {
  lcd.setCursor(5, 0);
  lcd.print("Pulse Gen");
  lcd.setCursor(0, 1);
  lcd.print("Pulse On  = ");
  lcd.setCursor(0, 2);
  lcd.print("Pulse Off = ");
  if (ponFlag == 0) {
    lcd.setCursor(12, 1);
    lcd.print("F1 ");
    
  }
  if (pofFlag == 0) {
    lcd.setCursor(12, 2);
    lcd.print("F2     ");
  }
  if (ponFlag == 1) {
    lcd.setCursor(12, 1);
    lcd.print(pon);
    lcd.print("  ");
  }
  if (pofFlag == 1) {
    lcd.setCursor(12, 2);
    lcd.print(pon);
    lcd.print("  ");
  }

  lcd.setCursor(0, 3);
  lcd.print("Esc= Edit : Ent= Run");
  freqNum = (pon + pof);
  freq = 1000 / (freqNum);
  char key = keypad.getKey();
  if (key != NO_KEY) {
    if (key == 'C') {
      lcd.clear();
      ponFlag = 0;
      pon = 1;
      pofFlag = 0;
      pof = 1;
      lcd.setCursor(7, 2);
      lcd.print("reset");
      delay(500);
    }
    if (key == 'A') {
      lcd.clear();
      lcd.setCursor(6, 2);
      lcd.print("Pulse On");
      delay(500);
      ponSet();
      lcd.clear();
    }
    if (key == 'B') {
      lcd.clear();
      lcd.setCursor(6, 2);
      lcd.print("Pulse Off");
      delay(500);
      lcd.clear();
    }
    if (key == 'E') {
      if ((ponFlag == 1) && (pofFlag == 1)) {
        lcd.clear();
        lcd.setCursor(6, 2);
        lcd.print("Running");
        runFlag = 1;
        delay(500);
        running();
        lcd.clear();
      }
      if (ponFlag != 1){
        lcd.clear();
        lcd.setCursor (3,2);
        lcd.print ("Set Pulse On");
        delay (500);
        lcd.clear();
        }
        if (pofFlag != 1){
        lcd.clear();
        lcd.setCursor (3,2);
        lcd.print ("Set Pulse Off");
        delay (500);
        lcd.clear();
        }
    }
  }
  
}


void running(){
  lcd.setCursor (5,0);
  lcd.print ("Pulse Gen");
  lcd.setCursor (6,1);
  lcd.print ("Running");
  lcd.setCursor (0,2);
  lcd.print ("On = ");
  lcd.print (pon);
  lcd.print ("   Off = ");
  lcd.print (pof);
  do{
    digitalWrite (pulseOut, HIGH);
    digitalWrite (LED, HIGH);
    delayMicroseconds (pon);
    digitalWrite (pulseOut, LOW);
    digitalWrite (LED, LOW);
    char key = keypad.getKey();
    if (key != NO_KEY){
      if (key = 'C'){
        runFlag = 0;
        loop();
      }
    }
  } while (runFlag == 1);
}

void ponSet() {
  ponFlag = 0;
  csr = 7;
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("Pulse On Time");
  lcd.setCursor(0, 1);
  lcd.print("On Time (uS) 1-");
  rem = 1000 - pon;
  lcd.print(rem);
  lcd.setCursor(0, 2);
  lcd.print("Pulse = ");
  do {
    char key = keypad.getKey();
    if (key != NO_KEY) {
      lcd.setCursor((csr), 2);
      lcd.print(key);
      csr++;

      if (key >= '0' && key <= '9') {  // only act on numeric keys
        ponString += key;              // append new character to input string
      } else if (key == 'E') {
        if (ponString.length() > 0) {
          ponInt = ponString.toInt();  // YOU GOT AN INTEGER NUMBER
          ponString = "";              // clear input
          if (ponString > (rem)) {
            lcd.clear();
            lcd.setCursor(4, 1);
            lcd.print("Too High");
            delay(100);
            ponSet();
          }
          if (ponInt <= (rem)) {
            pon = ponInt;
            ponFlag = 1;
          }
        }
      } else if (key == 'C') {
        ponString = "";  // clear input
        ponFlag = 0;
        loop();
      }
    }
  } while (ponFlag == 0);
}

in order to enter the number, I used the multiple digit entry example on this page to base my code on...

How to input a multiple digits number using the keypad | Arduino FAQs (arduinogetstarted.com)

1 Like
                {
                    ponInt = ponString.toInt();  // YOU GOT AN INTEGER NUMBER
                    ponString = "";              // clear input
                    if (ponString > (rem))

Did you mean to compare ponInt to rem rather than ponString ?

Yes, thank you...

THANK YOU :smile: :+1: :smile:

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