Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of AnalogInterrupt by
main.cpp
- Committer:
- rossatmsoe
- Date:
- 2017-08-12
- Revision:
- 0:db459a4b2e6b
File content as of revision 0:db459a4b2e6b:
/*
AnalogInterrupt
 
 The circuit:
 * Three analog comparators
 * photoresistor from comparator + inputs to +3.3V
 * 10K resistor from comparator + inputs to ground
 * Four resistors (1K or more) in series from ground to +3.3V
 * Junction of each resistor to a single comparator - input
 * Outputs of comparators to digital pins D2, D3, D4
 
 created 1 Jul 2009
 modified 9 Apr 2012
 by Tom Igoe 
 
 modified for Nucleo / mbed 12 Aug 2017
 by Sheila Ross
 
 This example code is in the public domain.
 
 */
#include "mbed.h"
// Define the interrupt pins
InterruptIn dark_dim(D2);
InterruptIn dim_medium(D3);
InterruptIn medium_bright(D4);
// Create a serial connection over our USB
Serial pc(USBTX, USBRX);
void dark();
void dim();
void medium();
void bright();
int main() {
  
    pc.baud(9600);  // Set serial communication speed
    dark_dim.fall(&dark);
    dark_dim.rise(&dim);
    dim_medium.fall(&dim);
    dim_medium.rise(&medium);
    medium_bright.fall(&medium);
    medium_bright.rise(&bright);
    while(1) {
        wait(1); 
    }
}
void dark() {
    pc.printf("dark\n");
}
void dim() {
    pc.printf("dim\n");
}
void medium() {
    pc.printf("medium\n");
}
void bright() {
    pc.printf("bright\n");
}
            
    