Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UltrasonicDemo.ino
- #include "Ultrasonic.h"
- void setup(){
- Serial.begin(SerialBaudRate); //115200
- while (!Serial) {delay(10);} //wait for serial to wake up
- UltrasonicSetup();
- }
- void loop(){
- UltrasonicLoop();
- }
- *********************************************
- //Excerpts from Ultrasonic.cpp
- void UltrasonicSetup() {
- Serial.begin(SerialBaudRate); //115200
- while (!Serial) {delay(10);} //wait for serial to wake up
- D_show_cursor(false); //disable cursor on display
- D_cls();
- D_position(0, 0);
- Serial.print(F("Ultrasonic library loaded"));
- pinMode(TRIGGER_PIN, OUTPUT); //TRIG(speaker pin)
- pinMode(ECHO_PIN, INPUT); //ECHO(microphone pin)
- attachInterrupt (digitalPinToInterrupt (ECHO_PIN), USInterruptTimer, CHANGE); //interrupt routine setup
- //attachPCINT(digitalPinToPCINT(ECHO_PIN), InterruptTimer, CHANGE); //when using PinChangeInterrupt.h
- delay(1000);
- D_cls();
- }
- *********************************************
- void UltrasonicLoop(){
- SendPulse(); //send a pulse to the ultrasonic sensor
- average = RunningAverage(average, echoTime);
- char keystroke = checkSerial();
- if (keystroke != -1){ //for key tracking
- D_position(0,68);
- Serial.print(F(" "));
- D_position(0,68);
- Serial.write(keystroke);
- Serial.print(F(" "));
- Serial.print(int(keystroke));
- }
- D_position(1,68); //display current distance reading in centimeters
- Serial.print(F(" "));
- D_position(1, 68);
- Serial.print(USGetDist());
- D_position(1, 76);
- Serial.print(F("Centimeters"));
- switch(state){ //state machine
- case 0 : normal(keystroke); break; //normal operation
- case 1 : Calibration(keystroke); break; //calibration
- case 2 : calPoint(keystroke,1); break; //set calibration point 1
- case 3 : calPoint(keystroke,2); break; //set calibration point 2
- case 4 : calPoint(keystroke,3); break; //set calibration point 3
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement