Last active
January 23, 2019 08:17
-
-
Save Conplug/31a4e859ae014e0f15345e7a883a07df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// Copyright (c) 2019 Conplug (https://conplug.com.tw) | |
// Author: Hartman Hsieh | |
// | |
// Description : | |
// None | |
// | |
// Connections : | |
// Plug "POT_BTN V1.0" module at "JA6D4". | |
// | |
// Required Library : | |
// None | |
// | |
int PinVal = 0; | |
unsigned long PreviousTriggerTime = 0; | |
void PciSetup(byte pin) | |
{ | |
*digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin | |
PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt | |
PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group | |
} | |
// | |
// Handle pin change interrupt for D0 to D7 here | |
// | |
ISR (PCINT2_vect) | |
{ | |
PinVal = digitalRead(4); | |
if (PinVal == 1) { // Key Down | |
if ((millis() - PreviousTriggerTime) > 300) { // Prevent trigger many times at one key pressing. | |
Serial.println("Key Down"); | |
PreviousTriggerTime = millis(); | |
} | |
} | |
} | |
void setup() { | |
Serial.begin(9600); | |
// | |
// Enable interrupt for D4 | |
// | |
PciSetup(4); | |
} | |
void loop() { | |
// | |
// Print the value of analog input. | |
// | |
Serial.println(analogRead(A6)); | |
delay (500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment