816Views6Replies
How do i key in a 4x4 matrix keypad input into arduino and control the brushless motor?
I need to use a 4x4 matrix keypad to key in the value ( or angle 0-180) using a servo library to spin a brushless motor. i was thinking of typing each character and then put them in an array. After that, change it to interger using atoi. how do i do that?? taking the pressed numbers from the keypad, put it in array and then change it to integer to run the bldc motor.?? help pleeeasseee.... an explanation and coding sample would be a great help..
Discussions
3 years ago
Why don't you try it and report back. You have the process worked out.
Answer 3 years ago
here's my code... but i have a new problem... the code only can read the any value between 103 till 180. Knowing that servo library have a value of 0-180... i tried to input any value from 0-102... the code does not read it and no spinning of the motor... i was wondering you can guide me on that..Here's my code
#include "Keypad.h"
#include <LiquidCrystal.h>
#include <Servo.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
Servo myservo;
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] =
{{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3}; //connect to the column pinouts of the keypad
int count=0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Servo");
lcd.begin(16,2);
myservo.attach(11);
}
void loop()
{
static char buffer[4];
static byte i = 0;
char key = keypad.getKey();
// i < 3: prevent buffer overflow
if ('0' <= key && key <= '9' && i < 3)
{
buffer[i] = key;
++i;
lcd.print(key);
}
else if (key == '#' && i > 0)
{
buffer[i] =0; // null-terminate buffer
Serial.print(buffer);
int value = atoi(buffer);
myservo.write(value);
i = 0;
}
}
Answer 2 years ago
I tried your code for my stepper motor project I couldn't display the "value" in my oled and what i did was to save "value" to and int x x=value; and then save x to another int a for example and send 'a' to my display
It works fine
Answer 3 years ago
The terminating condition for your buffer collection is wrong. It will ONLY accept three numbers, not one or two.
Answer 3 years ago
1+
3 years ago
You only need a full-wave bridge...
If the BLDC needs less then 300ma a dual 555 = 556 can turn it for you....
Click a pic to see entire image..