PERCOBAAN 4 KONDISI 4
Keypad 1 hingga 9 memberikan PWM 255-0 dengan jarak PWM antar Key 28
2. Rangkaian Simulasi
[Kembali]
Listning Program:
#include <Servo.h>
#include <Keypad.h>
Servo servoMotor;
const int servoPin = 11; // PWM pin for servo
const int numRows = 4; // Number of rows in keypad
const int numCols = 3; // Number of columns in keypad
char keys[numRows][numCols] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[numRows] = {9, 8, 7, 6}; // Rows 0 to 3
byte colPins[numCols] = {5, 4, 3}; // Columns 0 to 2
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);
// Function to map keypad values to PWM values
int mapKeypadToPWM(char key) {
// Convert the character to integer
int value = key - '0';
// Calculate PWM value with a gap of 28 between keys
int pwmValue = 255 - (value * 28);
// Ensure PWM value stays within 0 to 255 range
pwmValue = max(0, min(255, pwmValue));
return pwmValue;
}
void setup() {
servoMotor.attach(servoPin);
servoMotor.write(90); // Initial position
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
// Perform actions based on the key pressed
switch (key) {
case '1':
// Set PWM value to 255
servoMotor.write(mapKeypadToPWM(key));
break;
case '2':
// Set PWM value to 227
servoMotor.write(mapKeypadToPWM(key));
break;
case '3':
// Set PWM value to 199
servoMotor.write(mapKeypadToPWM(key));
break;
case '4':
// Set PWM value to 171
servoMotor.write(mapKeypadToPWM(key));
break;
case '5':
// Set PWM value to 143
servoMotor.write(mapKeypadToPWM(key));
break;
case '6':
// Set PWM value to 115
servoMotor.write(mapKeypadToPWM(key));
break;
case '7':
// Set PWM value to 87
servoMotor.write(mapKeypadToPWM(key));
break;
case '8':
// Set PWM value to 59
servoMotor.write(mapKeypadToPWM(key));
break;
case '9':
// Set PWM value to 31
servoMotor.write(mapKeypadToPWM(key));
break;
default:
break;
}
}
}
3. Video [Kembali]
Pada kondisi yang diminta, yaitu simulasi rangkaian yang melibatkan komponen , keypad dan PWM dimana merupakan implementasi penggunaan PWM dengan input keypad. Ketika masing masing tombol keyped ditekan dari 0-9 maka PWM akan bergerak dengan kondisi memberikan PWM 255-0 dengan jarak PWM antar Key 28
5. Link Download
[Kembali]
- HTML [disini]
- File Simulasi [disini]
- Video [disini]
- Datasheet LCD lm016l [disini]
- Datasheet Keypad [disini]
- Datasheet Arduino Uno [disini]
0 comments:
Posting Komentar