Hi, I am having a problem whilst trying to create an interface between my Arduino and my PC, I have loaded the following code onto my Arduino
int led_pin = 13;
int interrupt_pin_a = 0; // Digital pin #2
int interrupt_pin_b = 1; // Digital pin #3
int signal_pin_a = 2; // Digital pin #2
int signal_pin_b = 3; // Digital pin #3
volatile int state_a = 0;
volatile int state_b = 0;
volatile unsigned long last_seen_millis = 0;
volatile int pause_counter = 0;
volatile int continue_counter = 0;
void setup(){
noInterrupts();
pinMode(led_pin, OUTPUT);
pinMode(signal_pin_a, INPUT );
pinMode(signal_pin_b, INPUT );
digitalWrite(led_pin, LOW);
Serial.begin(9600);
state_a = 0;
state_b = 0;
attachInterrupt(interrupt_pin_a, detect_a, RISING);
attachInterrupt(interrupt_pin_b, detect_b, RISING);
interrupts();
}
void detect_a() {
noInterrupts();
state_a++;
interrupts();
}
void detect_b() {
noInterrupts();
state_b++;
interrupts();
}
void loop(){
if(state_a > 0 && state_b > 0) {
// We saw a falling signal. This indicates
// that the magnet sensor has gone past,
// and we can issue a message over the serial
// port.
noInterrupts();
state_a = 0;
state_b = 0;
// Indicate signal with LED
digitalWrite(led_pin, HIGH);
Serial.println( millis() );
digitalWrite(led_pin, LOW);
interrupts();
last_seen_millis = millis();
// Wait at least 100 milliseconds
// before trying to detect the next interrupt
while( millis() < ( last_seen_millis + 100 ) ) {
state_a = 0;
state_b = 0;
}
}
// We don't see an interrupt from state_a, but
// we should check if we've left the sensor
// in pause mode
while( digitalRead(signal_pin_a) ) {
digitalWrite(led_pin, HIGH);
last_seen_millis = millis();
// Wait at least 100 milliseconds
// before trying to see if we're
// paused
while( millis() < ( last_seen_millis + 100 ) ) {
// Noop
}
// We've waited 100 milliseconds and we're still
// reading positive signal
pause_counter++;
// If we've seen this behavior for 5 seconds,
// pause the exercise.
if(pause_counter > 50) {
Serial.println( "pause" );
last_seen_millis = millis();
while( millis() < ( last_seen_millis + 10000 ) ) {
// Noop
}
}
}
pause_counter = 0;
digitalWrite(led_pin, LOW);
// We don't see an interrupt from state_b, but
// we should check if we've left the sensor
// in continue mode
while( digitalRead(signal_pin_b) ) {
digitalWrite(led_pin, HIGH);
last_seen_millis = millis();
// Wait at least 100 milliseconds
// before trying to see if we're
// paused
while( millis() < ( last_seen_millis + 100 ) ) {
// Noop
}
// We've waited 100 milliseconds and we're still
// reading positive signal
continue_counter++;
// If we've seen this behavior for 5 seconds,
// pause the exercise.
if(continue_counter > 50) {
Serial.println( "continue" );
last_seen_millis = millis();
while( millis() < ( last_seen_millis + 10000 ) ) {
// Noop
}
}
}
continue_counter = 0;
digitalWrite(led_pin, LOW);
}
This is some code from another persons project attempting to achieve a similar result however they are using the Arduino Uno Board. I am a complete beginner to this, have never done microcontroller programming before and have little circuit design experience. The board seems to be sensing the magnet passing by the read switches, however when using the serial monitor that came with the Arduino software nothing seems to be coming up on the screen, I have also downloaded a separate more powerful serial port monitor by Eltima and have had no luck with that.
Please could someone tell advise me how to rectify this I will attach some pictures of my circuit to give some extra insight. Also the green power LED flashes off when I pass the magnet by the reed switches is this correct I really don't know :~ [/https://www.facebook.com/photo.php?fbid=10152939111220646&set=a.10151367977080646.820068.655585645&type=1&theater]
[/https://www.facebook.com/photo.php?fbid=10152939091700646&set=a.10151367977080646.820068.655585645&type=1&theater]
[/https://www.facebook.com/photo.php?fbid=10152939091260646&set=a.10151367977080646.820068.655585645&type=1&theater]
[/https://www.facebook.com/photo.php?fbid=10152939090840646&set=a.10151367977080646.820068.655585645&type=1&theater]