Simple library for reading distance from SRF02 Ultrasonic Sensor in I2C mode.

Fork of SRF02 by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
garyk6666
Date:
Thu May 05 08:56:36 2016 +0000
Parent:
2:ab1c9250d9fb
Commit message:
2.0

Changed in this revision

main.cpp Show diff for this revision Revisions of this file
main.h Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 05 08:46:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#include "main.h"
-
-int main()
-{
-    init_K64F();//the k64f initialization
-    button.fall(&green);//for interruptIn
-    button.mode(PullNone);//for interruptIn
-    lcd.init();//the lcd initialization
-    wait(1.0);
-    lcd.printString("Distance",18,1);//Display the Distance
-    lcd.printString("Detector",18,3);//Display the Detector
-    wait(1.0);
-    lcd.clear();//clear the display
-    lcd.printString("Kai yuan!",18,2);//Display the name Kai yuan
-    lcd.printString("200967075",18,4);//Display the 200967075
-    wait(2.0);
-    lcd.clear();//clear the display
-    button.mode(PullDown);//for interruptIn
-
-    while(1) {
-        if(yesno == true) {
-            char buffer[14];// each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
-            buzzer.period(0.001);  // try 1 kKz
-            buzzer = 0.5;  // turn on (square wave)
-            wait(1.0);
-            lcd.clear();//clear the display
-            int distance=sensor.getDistanceCm();//get distance
-            int length = sprintf(buffer,"D = %d cm",distance);
-            if (length <= 14)  {// if string will fit on display
-                lcd.printString(buffer,0,1);
-            }
-            lcd.drawLine(0,24,0,48,1);//display the line
-            lcd.drawRect(distance/5,31,10,5,1);//display the rectangle
-            lcd.drawCircle(distance/5+3,37,1,1);//display the circle
-            lcd.drawCircle(distance/5+7,37,1,1);//display the circle
-            lcd.refresh();
-            ticker.attach(&green1,0.1);//for led flashing
-
-        }
-
-        else {
-            lcd.clear();
-            lcd.printString("Are you ready?",0,2);
-            buzzer = 0.0;  // turn off (0% duty cycle)
-            ticker.detach();
-            green_led = green_led;//turn off the led
-        }
-        r_led = 1;
-        wait(0.5);
-    }
-}
-
-void init_K64F()
-{
-    // on-board LEDs are active-low, so set pin high to turn them off.
-    r_led = 1;
-    g_led = 1;
-    b_led = 1;
-
-    // since the on-board switches have external pull-ups, we should disable the internal pull-down
-    // resistors that are enabled by default using InterruptIn
-    button.mode(PullNone);
-    button.mode(PullNone);
-
-}
-
-void green()
-{
-    yesno=!yesno;//true or false
-}
-void green1()
-{
-    green_led =! green_led;//make led light
-}
--- a/main.h	Thu May 05 08:46:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-
-/**
-@file main.h
-@brief Header file containing functions prototypes, defines and global variables.
-@brief Shows examples of creating Doxygen documentation.
-@brief Acknowledgements to Craig A. Evans's N5110 Library.
-@brief Acknowledgements to Craig A. Evans's SRF02 Library.
-@brief Revision 1.0.
-@author Kai Yuan
-@date   May 2016
-*/#include "mbed.h"
-#include "SRF02.h"
-#include "N5110.h"
-#include "SDFileSystem.h"
-
-/**
-@namespace SRF02_sensor
-@brief GPIO output for status LED
-*/
-SRF02 sensor(I2C_SDA,I2C_SCL);
-
-
-
-
-
-Serial serial(USBTX, USBRX);
-/**
-@namespace N5110_lcd
-@brief LCD Display
-*/
-N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
-/**
-@namespace r_led
-@brief red led
-*/
-DigitalOut r_led(LED_RED);
-/**
-@namespace g_led
-@brief green led
-*/
-DigitalOut g_led(LED_GREEN);
-/**
-@namespace b_led
-@brief blue led
-*/
-DigitalOut b_led(LED_BLUE);
-// K64F on-board switches
-/**
-@namespace button
-@brief button connection;
-*/
-InterruptIn button(PTB18);
-
-Ticker ticker;
-/**
-@namespace buzzer
-@brief buzzer connection;
-*/
-PwmOut buzzer(PTA2);
-/**
-@namespace  green_led
-@brief led connection;
-*/
-PwmOut green_led(PTC2);
-
-volatile bool yesno = false;/*!<create struct variable*/
-
-/**
- Initializing on board LEDS 
-*/
-void green1();
-
-/**
-  Changing the variable 
-*/
-void green();
-
-/**
- Initializing the k64F 
-*/
-void init_K64F();
-