I fixed your error, but I can’t make heads or tails of what you are trying to do with the keypad data. I mean I KNOW what you want to do, but your code has no relation with the keypad data. How are you calculating the RPM?
“NewData” is the new mapped variable from the keypad data. Instead of mapping the data, why not just enter 0 - 255 and get rid of the map altogether?
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
|| @Edited by HazardsMind 1/6/2013
*/
#include <Keypad.h>
int keyIn;
int currentCommand = 0;
char Data[5];
long NewData=0;
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] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
///////////encoder///////////////////
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
////////motor//////////////////
int cw = 7;
int pwm = 6;
int button = 8;
int LED = 9;
int but = 0;
void setup(){
Serial.begin(9600);
pinMode(cw,OUTPUT);
pinMode(pwm,OUTPUT);
pinMode(button,INPUT);
pinMode(LED,OUTPUT);
////////key in data for encoder ///////////
digitalWrite(2, HIGH);
attachInterrupt(0, rpm_fun(), RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop(){
but = digitalRead(button);
if (but == HIGH)//clockwise
{
int key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
{
if (key != '*') {
Data[currentCommand++] = key;
Serial.println(key);
keyIn = atoi(Data);
/* */ NewData = map(keyIn, 0 , 1400, 0, 255); //Right here is the new line
//this should print the first digit in it's same spot and the 2nd and 3rd will follow like normal, when inputted.
}
else {
//keyIn = atoi(Data);
//lcd.setCursor(6,1);
//lcd.print(keyIn);
//lcd.print(" ");
//just to tell you * was pressed
Serial.println(keyIn);
analogWrite(LED, keyIn);
while(currentCommand !=0){ // This can be used for any array size,
Data[currentCommand--] = 0; //clear for new data
}
}
}
}
else {
}
if(rpmcount >=20)
{//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
float rpm = float (14*60)/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm,4);
}
}
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}