The Hardware
Flash an LED
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while ( true)
{
Led.Write(!Led.Read())
Thread.Sleep(500)
}
Digital Input – Polled
InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
led.Write(button.Read());
Thread.Sleep(1000);
}
Digital Input – Interrupt
static OutputPort interuptled = new OutputPort(Pins.ONBOARD_LED, false);
InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);
Thread.Sleep(Timeout.Infinite);
static void button_OnInterrupt(uint data1, uint data2, DateTime time)
{
interuptled.Write(!interuptled.Read());
}
Analog Input
AnalogInput Sensor = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);
while ( true)
{
Debug.Print( "Value " + Sensor.Read().ToString("F2"));
Thread.Sleep(500);
}
Pulse Width Modulation Output
AnalogInput brightness = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);
PWM led = new PWM(PWMChannels.PWM_PIN_D5, 1000, 0.0, false);
led.Start();
while (true)
{
Debug.Print("Brightness " + led.DutyCycle.ToString("F2"));
led.DutyCycle = brightness.Read();
Thread.Sleep(500);
}
led.Stop();
Power Consumption Monitor
- Energy Monitor Shield USD 23.00
- Non-invasive current Sensor 30A USD10.80
Developing the software for the Energy Monitor Shield
- Read the buttons using an Analog input
- Calibrate the sensor for the offset voltage
- Calculate the RMS current based on the sensor outputs and AnalogInput range
- Display the power consumption on the Nokia 5110 display
- Compensate for Noise on the AnalogInput
- Upload the power consumption information to xively
Robot
Developing the software
- Determine the distance to objects
- Control the speed & direction of the motors using a Motor Shield Driver
- Basic obstacle avoidance
- Avoid obstacles using a state machine
- Fine tune the motor speeds using a rotary encoder
- Connect the GPS
- Upload the position information to Xively
Heart Rate Monitor
Developing the software
- Read the buttons using an AnalogInput
- Count the number of button presses using an InterruptPort and a Timer
- Determine the pulse rate in BPM by counting
- Determine the average pulse rate in BPM
- Display and manage the pulse rate info on the DFRobot 16×2 Lcd Shield
- Upload the pulse rate information to xively