Commit e4fb89e2 authored by Patrick's avatar Patrick

Merge branch 'master' of git.defproc.co.uk:ea/inter-micro

parents 2f000fdb e368ba2c
Indermediate Microcontrollers
-----------------------------
# Indermediate Microcontrollers
Course materials for the Intermediate Microcontrollers course.
* [Course text](inter-micro.md)
* [Example sketches](examples/)
* [Example sketches](red_peg/examples/)
/*
* Reading the MB 7060 sensor to give distance readings
*
* It is recommended to providing an external power supply
* as the maxbotix ultrasound sensors can draw more than
* the 0.5A that a USB port is able to supply
*
* Powering from USB only may lead to some crashes/restarts
* because of the current draw
*
*/
#include <red_peg.h>
red_peg RP;
void setup() {
delay(2000);
RP.begin();
Serial.begin(BAUD);
Serial.println("starting rp_maxbotix");
}
void loop() {
RP.sensorsOn();
// wait long enough for the ultrasound to start up
delay(500);
t_SensorData depth = RP.get(ANA);
RP.sensorsOff();
if (depth.sensor == ANA) {
RP.print_data(depth);
Serial.print("Value: ");
Serial.print(depth.reading);
Serial.print(", ");
Serial.print(RP.volts(depth));
Serial.print(" V, ");
Serial.print(RP.distance(depth));
Serial.print(" cm");
Serial.println();
delay(5000);
}
}
......@@ -217,12 +217,12 @@ long red_peg::level(t_SensorData data_record, long max_level)
}
}
float red_peg::distance(t_SensorData data_record)
long red_peg::distance(t_SensorData data_record)
{
if (data_record.the_command == ANA) {
long distance = map(data_record.the_reading, 0, MAX_20MA, 0, 765L);
return distance;
return distance; // in cm
} else {
return -1.0;
return -1L;
}
}
......@@ -115,7 +115,7 @@ public:
float level(t_SensorData data_record, double max_level);
float level(t_SensorData data_record, float max_level);
// TODO:
float distance(t_SensorData data_record); // Ultrasonic distance reading
long distance(t_SensorData data_record); // Ultrasonic distance reading
};
#endif // red_peg_h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment