smeagol109
Newbie level 4
- Joined
- May 4, 2014
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 55
Hey guys, im developing an air hockey table and i am kinda confused with the code, i want to make a program using IR leds that counts the amount of goals in 1 goal. So i will have a pair of IR leds in the goal, and when the ball interrupts the beam it will count has 1 goal, this will be updated in a display installed on the table. Here is what i got so far.
I dont know if the code is complete, nor 100% correct, if you could help me i would apreciate it alot, it would mean the world to me!!
Thanks in advance.
Code dot - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 /* * Optical Tachometer * * Uses an IR LED and IR phototransistor to implement an optical tachometer. * The IR LED is connected to pin 13 and ran continually. * Pin 2 (interrupt 0) is connected across the IR detector. * */ int ledPin = 13; // IR LED connected to digital pin 13 volatile byte goalcount; // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void golos() { //Update count goalcount++; } void setup() { lcd.begin(16, 2); // intialise the LCD //Interrupt 0 is digital pin 2, so that is where the IR detector is connected //Triggers on FALLING (change from HIGH to LOW) attachInterrupt(0, golos, FALLING); //Turn on IR LED pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); goalcount = 0; } void loop() { //Update goals every second delay(1000); detachInterrupt(0); lcd.clear(); lcd.print("Golos"); lcd.setCursor(0,1); lcd.print(goalcount); //Restart the interrupt processing attachInterrupt(0, golos, FALLING); }
I dont know if the code is complete, nor 100% correct, if you could help me i would apreciate it alot, it would mean the world to me!!
Thanks in advance.
Last edited by a moderator: