krnl 1
Loading...
Searching...
No Matches
isrsimple01.ino
Go to the documentation of this file.
1
2
3
5{
6 Serial.println(F("Interrupt test program by JDN"));
7 Serial.println(F("-----------------------------"));
8 Serial.println(F("Program will put a square wave on pin 10 with a frequency of 500 Hz"));
9 Serial.println(F("You shall connect pin 10 to pin 2"));
10 Serial.println(F("And an interrupt service routine(ISR) will count nr of interrupts on pin 2"));
11 Serial.println(F("it will count falling levels"));
12 Serial.println(F("DONT use delay inside your ISR ! "));
13 Serial.println(F("Count should go up approx 500 each second"));
14 Serial.println(F("---"));
15 Serial.println(F("An experiment"));
16 Serial.println(F("Try to pull up wire from pin 10(500 Hz output)"));
17 Serial.println(F("now - try to touch metal shield at usb plug (which is ground)"));
18 Serial.println(F("every time you touch the shield (GROUND) you will see a count"));
19 Serial.println(F("and !!! observe you will get many counts even if you touch very rapid"));
20 Serial.println(F("it's called contact bounce "));
21 Serial.println(F("---"));
22 Serial.println(F("try to keep it up in free air "));
23 Serial.println(F("you should observe some irregular increase in count - weird"));
24 Serial.println(F("it's because you have an open input and the wire acts like an antenna"));
25 Serial.println(F("in pinMode line change INPUT to INPUT_PULLUP and recompile"));
26 Serial.println(F("now you will (hopfully) see no increase in count when wire is not connected to pin 10"));
27 }
28
29volatile int cnt = 0;
30
31void myISR()
32{
33 cnt++;
34}
35
36void setup() {
37 Serial.begin(9600);
38 delay(1000);
40 pinMode(2, INPUT_PULLUP); // ISR pin
41 attachInterrupt(digitalPinToInterrupt(2), myISR, FALLING);
42 // Mode can be FALLING, RISING, CHANGE, LOW(when low), HIGH(high)
43
44 delay(1000);
45
46 analogWrite(10, 127); // just start PWM on pin 10
47
48}
49
50void loop() {
51 // put your main code here, to run repeatedly:
52
53 delay(1000);
54 Serial.println(cnt);
55}
void myISR()
Definition ka01isr.ino:60
volatile int cnt
void setup()
void instructions()
void myISR()
void loop()