Offline
Newbie
Karma: 0
Posts: 22
|
 |
« on: January 03, 2013, 06:30:26 am » |
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
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: January 03, 2013, 07:48:05 am » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #2 on: January 04, 2013, 01:39:16 am » |
yeay, i did do my search on keypad prob....but no related coding for my prob...  .....
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #3 on: January 04, 2013, 05:54:47 am » |
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
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #4 on: January 04, 2013, 09:55:44 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #5 on: January 06, 2013, 09:24:13 pm » |
/* @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
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #6 on: January 06, 2013, 09:56:54 pm » |
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 }
|
|
|
|
« Last Edit: January 06, 2013, 10:01:36 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
|