MAKECourse
  • Home
  • About
  • Course Materials
    • Software
    • Course Kits
    • TA hours
  • Videos
    • Intro to Programming Videos
    • Advanced Topics >
      • DAC and ADC Tutorial
      • SD Card Data Logging
      • DC Motor Control
  • Schedule
    • Syllabus
  • Student Projects
    • Awesome Prizes
    • Fall 2020 Projects
    • Fall 2016 Awesome Prize Winners
    • Fall 2016 Projects
    • Spring 2016 Awesome Prize Winners
    • Spring 2016 Projects
    • Fall 2015 Awesome Prize Winners
    • Fall 2015 Projects
    • Spring 2015 Awesome Prize Winners
    • Spring 2015 Projects
    • Fall 2014 Projects
    • Spring 2014 Projects

Week 7. Segment 1: Libraries

This segment focuses on the development of C++ libraries for the control of devices connected to the Arduino.  

Goals:

  • Learn to design C++ libraries.
  • Design a library for the control of an Arduino Kit component.

In-Class Project:
  • Write a library for the control of the ultrasound proximity sensor in the Arduino Kit.
  • Tasks: 
      1. Write a class for proximity sensor. Call it “HCSR04ProxSensor”
        1. It is good practice to use the actual device name for such a library.
      2. Develop the following methods:
      3. Constructor: void HCSR04ProxSensor:: HCSR04ProxSensor(int triggerPin, int echoPin). This is the ‘constructor’, which defines the pins that are used to connect the sensor
      4. int HCSR04ProxSensor:: readSensorInches(). This reads the sensor in inch units.
      5. float HCSR04ProxSensor:: readSensorCentimeters(). This reads the sensor in cm units.
      6. float HCSR04ProxSensor::getLastValue(). This returns the last measurement that was made. this is a convenient method if you wanted, for example, write some code that measures distance changes. You could ask the sensor: ‘what did you measure the last time’, and then compare with the current value that would be returned by . readSensorInches().
      7. Generate the header .h file and the .cpp file and save them in their own folder in the Library folder.
  • Modify the provided code including the library and experiment with the methods.

Materials for this segment:

  • Read the Arduino.cc page on writing libraries.
  • Watch the videos on the right.
  • Get the user manual for the HC-SR04 distance sensor
  • Arduino sketches featured in the tutorial and the In-Class Project (see below the videos on the right)

Arduino sketch and library used in the above tutorial:
led_flasher_classinlibrary.zip
File Size: 1 kb
File Type: zip
Download File

DigitalPin Library files necessary for compiling the above sketch:
digitalpin_makecourse.zip
File Size: 3 kb
File Type: zip
Download File

icp_proximitsensor.zip
File Size: 0 kb
File Type: zip
Download File

[Home] [Course Materials] [Syllabus] [Student Projects] [Contact]
Powered by Create your own unique website with customizable templates.