Pages: [1]   Go Down
Author Topic: 4x 3 matrix Keypad control speed motor  (Read 1245 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey guys, im trouble to find project of using 4x3 keypad to control the speed of motor (pwm). anyone can share ? or give some idea how to map the keypad number for pwm. thanx in advanced ...

my project idea is to key in number from keypad ("1234") then use ("#") to enter the number and map it to pwm... im using dc motor as for my project..
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you by any chance do a search in the forum for 4x3 keypad? Me and a few other people helped one guy with a keypad, and his code is somewhere in this forum. You just need to find it.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeay, i did do my search on keypad prob....but no related coding for my prob... smiley-cry .....
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You did a search in this forum and found nothing? Funny, because I found this. It's not 100% what you want to do but if you tweak it, it will work.
http://arduino.cc/forum/index.php/topic,137352.30.html
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeay, i had test it..thx hazard!!! i really appreciate it.... thx a lot man.... have a gud day!!!!>.. smiley-lol smiley-lol smiley-lol smiley-lol smiley-lol
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>

int keyIn;
int currentCommand = 0;
long DatA =0;


char Data[5];
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;
    Data = map(Data, 0 , 1400, 0, 255);
    Serial.println(key);
    keyIn = atoi(Data);
   
       //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
 }
 

im trouble in mapping whereby there is error "invalid conversion from char to long int"....... can anyone help me... thx in advanced
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3487
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Code:
/* @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
}

« Last Edit: January 06, 2013, 10:01:36 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Pages: [1]   Go Up
Jump to: