How To Use Digital Inputs; Reading Bumper Switches - Raspberry Pi RoboPi User Manual

Hide thumbs Also See for RoboPi:
Table of Contents

Advertisement

RoboPi v1.00

How to use Digital Inputs

Reading Bumper Switches

Probably the simplest digital input possible is a switch.
<insert schematic of two bumper switches, 100k pullup to 5v, shorts to ground when closed>
#include <stdio.h>
#include "RoboPiLib.h"
#define LEFT_BUMPER
#define RIGHT_BUMPER 23
#define PRESSED 0
int main(int argc, char *argv[]) {
RoboPiInit("/dev/ttyAMA0",115200);
pinMode(LEFT_BUMPER, INPUT);
pinMode(RIGHT_BUMPER, INPUT);
while (1) {
if (digitalRead(LEFT_BUMPER)==PRESSED)
if (digitalRead(RIGHT_BUMPER)==PRESSED)
sleep(1); // only check once per second
}
}
http://Mikronauts.com
User Manual v0.85
22
puts("Left Bumper Pressed");
puts("Right Bumper Pressed");
Copyright 2014 William Henning
17
2014-01-27

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RoboPi and is the answer not in the manual?

Questions and answers

Table of Contents