|
Akos Maroy's scripts
xbee_base: a very simple xbee_base application, that collects the data
sent by other xbee-enabled arduinos.
an alternative approach is to just remove the CPU from the arduino
board, re-jumper the XBee shield, and just read all the input from the
XBee shield direct via serial
xbee_sensor: a dummy sensor just sending stuff through the XBee shield
rangefinder: the rangefinder attachment we used with Andor to do the
range-based flash application
motionsensor: similar to above, an interface to the memsic motion sensor
I had there
all the code is proper C++ code (well, C mostly), that compiles to the
arduino using a Makefile. but, if you just remove the #include and the
main() function, you get an arduino 'patch', that can be pasted into the
arduino's processing-like editor.
Akos
#include
/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave
* arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
/* Ultrasound Sensor
*------------------
*
* Reads values (00014-01199) from an ultrasound sensor (3m sensor)
* and writes the values to the serialport.
*
* www.xlab.se | www.0j0.org
* copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
*
*/
int ultraSoundSignal = 8; // Ultrasound signal pin
int ultrasoundValue = 0;
int ledPin = 13; // LED connected to digital pin 13
void setup() {
beginSerial(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
}
int getDistance(int ultraSoundPin) {
int timecount = 0;
int val = 0;
/* Send low-high-low pulse to activate the trigger pulse of the sensor
* -------------------------------------------------------------------
*/
pinMode(ultraSoundPin, OUTPUT); // Switch signalpin to output
digitalWrite(ultraSoundPin, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundPin, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundPin, LOW); // Holdoff
/* Listening for echo pulse
* -------------------------------------------------------------------
*/
pinMode(ultraSoundPin, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundPin); // Append signal value to val
while (val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundPin);
}
while (val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundPin);
timecount = timecount +1; // Count echo pulse time
}
return timecount;
}
void loop() {
/* Writing out values to the serial port
* -------------------------------------------------------------------
*/
ultrasoundValue = getDistance(ultraSoundSignal);
//serialWrite('A'); // Example identifier for the sensor
printInteger(ultrasoundValue);
//serialWrite(10);
//serialWrite(13);
//serialWrite(' ');
serialWrite(10);
serialWrite(13);
serialWrite('\0');
/* Lite up LED if any value is passed by the echo pulse
* -------------------------------------------------------------------
*/
if(ultrasoundValue > 0){
digitalWrite(ledPin, HIGH);
}
/* Delay of program
* -------------------------------------------------------------------
*/
delay(100);
}
#include
/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave
* arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
static int state;
static const int OUT_PORT = 13;
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
void setup()
{
pinMode(OUT_PORT, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) {
state = Serial.read();
switch (state) {
case 'H':
digitalWrite(OUT_PORT, HIGH); // sets the LED off
break;
case 'L':
digitalWrite(OUT_PORT, LOW); // sets the LED off
break;
default:
break;
}
}
}
#include
/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave
* arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
static int state;
static const int OUT_PORT = 13;
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
void setup()
{
pinMode(OUT_PORT, OUTPUT); // sets the digital pin as output
state = 0;
Serial.begin(9600);
}
void loop()
{
digitalWrite(OUT_PORT, HIGH); // sets the LED on
Serial.println('H');
delay(1000); // waits for a second
digitalWrite(OUT_PORT, LOW); // sets the LED off
Serial.println('L');
delay(1000); // waits for a second
}
#include
/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave
* arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
/* Accelerometer Sensor
* --------------------
*
* Reads an 2-D accelerometer
* attached to a couple of digital inputs and
* sends their values over the serial port; makes
* the monitor LED blink once sent
*
*
* www.0j0.org
* copyleft 2005 K3 - Malmo University - Sweden
* @author: Marcos Yarza
* @hardware: Marcos Yarza
* @project: SMEE - Experiential Vehicles
* @sponsor: Experiments in Art and Technology Sweden, 1:1 Scale
*/
int ledPin = 13;
int xaccPin = 7;
int yaccPin = 6;
int value = 0;
int accel = 0;
char sign = ' ';
int timer = 0;
int count = 0;
void setup() {
beginSerial(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT);
pinMode(xaccPin, INPUT);
pinMode(yaccPin, INPUT);
}
/* (int) Operate Acceleration
* function to calculate acceleration
* returns an integer
*/
int operateAcceleration(int time1) {
return abs(8 * (time1 / 10 - 500));
}
/* (void) readAccelerometer
* procedure to read the sensor, calculate
* acceleration and represent the value
*/
void readAcceleration(int axe){
timer = 0;
count = 0;
value = digitalRead(axe);
while(value == HIGH) { // Loop until pin reads a low
value = digitalRead(axe);
}
while(value == LOW) { // Loop until pin reads a high
value = digitalRead(axe);
}
while(value == HIGH) { // Loop until pin reads a low and count
value = digitalRead(axe);
count = count + 1;
}
timer = count * 18; //calculate the teme in miliseconds
//operate sign
if (timer > 5000){
sign = '+';
}
if (timer < 5000){
sign = '-';
}
//determine the value
accel = operateAcceleration(timer);
//Represent acceleration over serial port
if (axe == 7){
printByte('X');
} else {
printByte('Y');
}
printByte(sign);
Serial.println(accel);
}
void loop() {
readAcceleration(xaccPin); //reads and represents acceleration X
readAcceleration(yaccPin); //reads and represents acceleration Y
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
}
|