Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Remy Martin
committed
Jul 6, 2020
1 parent
e0dedb9
commit fc816f4
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"board": "arduino:avr:uno", | ||
"sketch": "arduino_push_keypad_2_digits.ino", | ||
"port": "COM16" | ||
} |
19 changes: 19 additions & 0 deletions
19
Arduino/arduino_push_keypad_2_digits/.vscode/c_cpp_properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"C:\\Users\\ArcHeR\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\**", | ||
"C:\\Users\\ArcHeR\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\**" | ||
], | ||
"forcedInclude": [ | ||
"C:\\Users\\ArcHeR\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino\\Arduino.h" | ||
], | ||
"intelliSenseMode": "msvc-x64", | ||
"compilerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe", | ||
"cStandard": "c11", | ||
"cppStandard": "gnu++14" | ||
} | ||
], | ||
"version": 4 | ||
} |
104 changes: 104 additions & 0 deletions
104
Arduino/arduino_push_keypad_2_digits/arduino_push_keypad_2_digits.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <Keypad.h> | ||
|
||
float xxx; | ||
unsigned long pwm1; | ||
|
||
const byte ROWS = 4; //four rows | ||
const byte COLS = 3; //three columns | ||
int inputA1; | ||
|
||
char keys[ROWS][COLS] = { | ||
{'1','2','3'}, | ||
{'4','5','6'}, | ||
{'7','8','9'}, | ||
{'*','0','#'} | ||
}; | ||
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad | ||
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad | ||
|
||
//Create an object of keypad | ||
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); | ||
|
||
void setup(){ | ||
pinMode(9, OUTPUT); | ||
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1B0) | _BV(WGM11); | ||
TCCR1B = _BV(WGM13) | _BV(CS11); | ||
|
||
Serial.begin(9600); | ||
} | ||
|
||
char key; | ||
int ckey = 0; | ||
void loop(){ | ||
|
||
|
||
key = keypad.getKey();// Read the key | ||
|
||
if (key != NO_KEY) | ||
{ | ||
Serial.println(key); | ||
} | ||
|
||
if(ckey == 2){ | ||
if(key == '0'){ //เมื่อ กด 0 เข้าเงื่อนไขนี้ | ||
inputA1 = 1024; // แทนค่า inputA1 ด้วย 1024 ที่ทำให้ PWM มี dutycycle 5 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '1'){ //เมื่อ กด 1 เข้าเงื่อนไขนี้ | ||
inputA1 = 900; // แทนค่า inputA1 ด้วย 900 ที่ทำให้ PWM มี dutycycle 10 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '2'){ //เมื่อ กด 2 เข้าเงื่อนไขนี้ | ||
inputA1 = 800; // แทนค่า inputA1 ด้วย 800 ที่ทำให้ PWM มี dutycycle 15 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '3'){ //เมื่อ กด 3 เข้าเงื่อนไขนี้ | ||
inputA1 = 700; // แทนค่า inputA1 ด้วย 700 ที่ทำให้ PWM มี dutycycle 20 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '4'){ //เมื่อ กด 4 เข้าเงื่อนไขนี้ | ||
inputA1 = 600; // แทนค่า inputA1 ด้วย 600 ที่ทำให้ PWM มี dutycycle 30 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '5'){ //เมื่อ กด 5 เข้าเงื่อนไขนี้ | ||
inputA1 = 500; // แทนค่า inputA1 ด้วย 500 ที่ทำให้ PWM มี dutycycle 40 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '6'){ //เมื่อ กด 6 เข้าเงื่อนไขนี้ | ||
inputA1 = 400; // แทนค่า inputA1 ด้วย 400 ที่ทำให้ PWM มี dutycycle 50 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '7'){ //เมื่อ กด 7 เข้าเงื่อนไขนี้ | ||
inputA1 = 300; // แทนค่า inputA1 ด้วย 300 ที่ทำให้ PWM มี dutycycle 60 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '8'){ //เมื่อ กด 8 เข้าเงื่อนไขนี้ | ||
inputA1 = 200; // แทนค่า inputA1 ด้วย 200 ที่ทำให้ PWM มี dutycycle 70 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '9'){ //เมื่อ กด 9 เข้าเงื่อนไขนี้ | ||
inputA1 = 100; // แทนค่า inputA1 ด้วย 100 ที่ทำให้ PWM มี dutycycle 80 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '*'){ //เมื่อ กด * เข้าเงื่อนไขนี้ | ||
inputA1 = 50; // แทนค่า inputA1 ด้วย 50 ที่ทำให้ PWM มี dutycycle 90 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
if(key == '#'){ //เมื่อ กด # เข้าเงื่อนไขนี้ | ||
inputA1 = 0; // แทนค่า inputA1 ด้วย 0 ที่ทำให้ PWM มี dutycycle 100 % | ||
Serial.println(String("Read inputA1 = ")+ inputA1); | ||
} | ||
|
||
ICR1 = 62.5; | ||
pwm1 = inputA1; | ||
|
||
xxx = float(pwm1); | ||
|
||
xxx = xxx * ICR1; | ||
|
||
xxx = xxx / 512; | ||
|
||
OCR1A = int(62.5-(xxx/2)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters