Hey - just have a quick question about subroutines.
How do I make a subroutine loop itself?
Thanks.
Hey - just have a quick question about subroutines.
How do I make a subroutine loop itself?
Thanks.
How do I make a subroutine loop itself?
Please explain what you want to do. There are many possible solutions.
I am prompting a user on an lcd screen to use a keypad to start a program. After pressing a key to start the program they will enter in their wage. The the wage is calculated in real time until they cancel out of the program.
Here is the code I have so far, thanks:
#include <SoftwareSerial.h>
#include <Keypad.h>
char N;
int I;
int ByteVar;
int NN;
int Remainder;
int Num_5;
#define ledpin 13
#define rxPin 11 // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :), see Reference pinMode
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// mySerial is connected to the TX pin so mySerial.print commands are used
// one could just as well use the software mySerial library to communicate on another pin
void setup(){
digitalWrite(ledpin, HIGH);
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // 9600 baud is chip comm speed
mySerial.print("?G216"); // set display geometry, 2 x 16 characters in this case
delay(500); // pause to allow LCD EEPROM to program
mySerial.print("?Bff"); // set backlight to ff hex, maximum brightness
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?s6"); // set tabs to six spaces
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?D00000000000000000"); // define special characters
delay(300); // delay to allow write to EEPROM
// see moderndevice.com for a handy custom char generator (software app)
mySerial.print("?f"); // clear the LCD
delay(10);
mySerial.print("Opportunity Cost");
mySerial.print("Calculator");
delay(4000);
mySerial.print("?f");
delay(10);
}
void loop(){
char key = keypad.getKey();
if(key) // same as if(key != NO_KEY)
{
switch (key)
{
case '#': pop();
break;
case '*':
mySerial.print(" welcome ");
mySerial.print(" ");
delay(2000);
mySerial.print("?f");
delay(10);
break;
default:
Serial.println(key);
}
}
else
{
mySerial.print("Pres # to begin ");
mySerial.print(" ");
delay(250);
}
}
void pop() {
mySerial.print("Thankyou ");
mySerial.print(" ");
delay(1000);
while (keypad.getKey() == NO_KEY)
{
mySerial.print("Enter your wage ");
mySerial.print(" ");
delay(500);
}
}
Look up examples and such of a technique called "state machine".
The short version, it is a technique to distinguish between states, where actions can be taken inside a state, or to change the state.