Removed non standard functions togglePin, toggleLED,isButtonPressed, and waitForButtonPress. And updated all examples that used these, to use other functions. Note togglePin was used internally in shiftOut. Also note, that some of these functions were replaced by the code that was inside the non standard function e.g inside togglePin. In the longer term these internal maple function calls need to be replaced by high level Arduino API calls like digitalRead and digitalWrite where applicable

This commit is contained in:
Roger Clark 2015-04-07 20:57:51 +10:00
parent 7bc0e0f015
commit 5dcfa4f1b0
25 changed files with 2359 additions and 2342 deletions

View File

@ -1,222 +1,224 @@
/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
/**
* @file wirish/include/wirish/io.h
* @brief Wiring-style pin I/O interface.
*/
#ifndef _WIRISH_IO_H_
#define _WIRISH_IO_H_
#include <libmaple/libmaple_types.h>
#include <boards.h>
/**
* Specifies a GPIO pin behavior.
* @see pinMode()
*/
typedef enum WiringPinMode {
OUTPUT, /**< Basic digital output: when the pin is HIGH, the
voltage is held at +3.3v (Vcc) and when it is LOW, it
is pulled down to ground. */
OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates
"low" by accepting current flow to ground
and "high" by providing increased
impedance. An example use would be to
connect a pin to a bus line (which is pulled
up to a positive voltage by a separate
supply through a large resistor). When the
pin is high, not much current flows through
to ground and the line stays at positive
voltage; when the pin is low, the bus
"drains" to ground with a small amount of
current constantly flowing through the large
resistor from the external supply. In this
mode, no current is ever actually sourced
from the pin. */
INPUT, /**< Basic digital input. The pin voltage is sampled; when
it is closer to 3.3v (Vcc) the pin status is high, and
when it is closer to 0v (ground) it is low. If no
external circuit is pulling the pin voltage to high or
low, it will tend to randomly oscillate and be very
sensitive to noise (e.g., a breath of air across the pin
might cause the state to flip). */
INPUT_ANALOG, /**< This is a special mode for when the pin will be
used for analog (not digital) reads. Enables ADC
conversion to be performed on the voltage at the
pin. */
INPUT_PULLUP, /**< The state of the pin in this mode is reported
the same way as with INPUT, but the pin voltage
is gently "pulled up" towards +3.3v. This means
the state will be high unless an external device
is specifically pulling the pin down to ground,
in which case the "gentle" pull up will not
affect the state of the input. */
INPUT_PULLDOWN, /**< The state of the pin in this mode is reported
the same way as with INPUT, but the pin voltage
is gently "pulled down" towards 0v. This means
the state will be low unless an external device
is specifically pulling the pin up to 3.3v, in
which case the "gentle" pull down will not
affect the state of the input. */
INPUT_FLOATING, /**< Synonym for INPUT. */
PWM, /**< This is a special mode for when the pin will be used for
PWM output (a special case of digital output). */
PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating
cycles of LOW and HIGH, the voltage on the pin
consists of alternating cycles of LOW and
floating (disconnected). */
} WiringPinMode;
/**
* Configure behavior of a GPIO pin.
*
* @param pin Number of pin to configure.
* @param mode Mode corresponding to desired pin behavior.
* @see WiringPinMode
*/
void pinMode(uint8 pin, WiringPinMode mode);
#define HIGH 0x1
#define LOW 0x0
/**
* Writes a (digital) value to a pin. The pin must have its
* mode set to OUTPUT or OUTPUT_OPEN_DRAIN.
*
* @param pin Pin to write to.
* @param value Either LOW (write a 0) or HIGH (write a 1).
* @see pinMode()
*/
void digitalWrite(uint8 pin, uint8 value);
/**
* Read a digital value from a pin. The pin must have its mode set to
* one of INPUT, INPUT_PULLUP, and INPUT_PULLDOWN.
*
* @param pin Pin to read from.
* @return LOW or HIGH.
* @see pinMode()
*/
uint32 digitalRead(uint8 pin);
/**
* Read an analog value from pin. This function blocks during ADC
* conversion, and has 12 bits of resolution. The pin must have its
* mode set to INPUT_ANALOG.
*
* @param pin Pin to read from.
* @return Converted voltage, in the range 0--4095, (i.e. a 12-bit ADC
* conversion).
* @see pinMode()
*/
uint16 analogRead(uint8 pin);
/**
* Toggles the digital value at the given pin.
*
* The pin must have its mode set to OUTPUT.
*
* @param pin the pin to toggle. If the pin is HIGH, set it LOW. If
* it is LOW, set it HIGH.
*
* @see pinMode()
*/
void togglePin(uint8 pin);
/**
* Toggle the LED.
*
* If the LED is on, turn it off. If it is off, turn it on.
*
* The LED must its mode set to OUTPUT. This can be accomplished
* portably over all LeafLabs boards by calling pinMode(BOARD_LED_PIN,
* OUTPUT) before calling this function.
*
* @see pinMode()
*/
static inline void toggleLED() {
togglePin(BOARD_LED_PIN);
}
/**
* If the button is currently pressed, waits until the button is no
* longer being pressed, and returns true. Otherwise, returns false.
*
* The button pin must have its mode set to INPUT. This can be
* accomplished portably over all LeafLabs boards by calling
* pinMode(BOARD_BUTTON_PIN, INPUT).
*
* @see pinMode()
*/
uint8 isButtonPressed(uint8 pin=BOARD_BUTTON_PIN,
uint32 pressedLevel=BOARD_BUTTON_PRESSED_LEVEL);
/**
* Wait until the button is pressed and released, timing out if no
* press occurs.
*
* The button pin must have its mode set to INPUT. This can be
* accomplished portably over all LeafLabs boards by calling
* pinMode(BOARD_BUTTON_PIN, INPUT).
*
* @param timeout_millis Number of milliseconds to wait until the
* button is pressed. If timeout_millis is left out (or 0), wait
* forever.
*
* @return true, if the button was pressed; false, if the timeout was
* reached.
*
* @see pinMode()
*/
uint8 waitForButtonPress(uint32 timeout_millis=0);
/**
* Shift out a byte of data, one bit at a time.
*
* This function starts at either the most significant or least
* significant bit in a byte value, and shifts out each byte in order
* onto a data pin. After each bit is written to the data pin, a
* separate clock pin is pulsed to indicate that the new bit is
* available.
*
* @param dataPin Pin to shift data out on
* @param clockPin Pin to pulse after each bit is shifted out
* @param bitOrder Either MSBFIRST (big-endian) or LSBFIRST (little-endian).
* @param value Value to shift out
*/
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value);
#endif
/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
/**
* @file wirish/include/wirish/io.h
* @brief Wiring-style pin I/O interface.
*/
#ifndef _WIRISH_IO_H_
#define _WIRISH_IO_H_
#include <libmaple/libmaple_types.h>
#include <boards.h>
/**
* Specifies a GPIO pin behavior.
* @see pinMode()
*/
typedef enum WiringPinMode {
OUTPUT, /**< Basic digital output: when the pin is HIGH, the
voltage is held at +3.3v (Vcc) and when it is LOW, it
is pulled down to ground. */
OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates
"low" by accepting current flow to ground
and "high" by providing increased
impedance. An example use would be to
connect a pin to a bus line (which is pulled
up to a positive voltage by a separate
supply through a large resistor). When the
pin is high, not much current flows through
to ground and the line stays at positive
voltage; when the pin is low, the bus
"drains" to ground with a small amount of
current constantly flowing through the large
resistor from the external supply. In this
mode, no current is ever actually sourced
from the pin. */
INPUT, /**< Basic digital input. The pin voltage is sampled; when
it is closer to 3.3v (Vcc) the pin status is high, and
when it is closer to 0v (ground) it is low. If no
external circuit is pulling the pin voltage to high or
low, it will tend to randomly oscillate and be very
sensitive to noise (e.g., a breath of air across the pin
might cause the state to flip). */
INPUT_ANALOG, /**< This is a special mode for when the pin will be
used for analog (not digital) reads. Enables ADC
conversion to be performed on the voltage at the
pin. */
INPUT_PULLUP, /**< The state of the pin in this mode is reported
the same way as with INPUT, but the pin voltage
is gently "pulled up" towards +3.3v. This means
the state will be high unless an external device
is specifically pulling the pin down to ground,
in which case the "gentle" pull up will not
affect the state of the input. */
INPUT_PULLDOWN, /**< The state of the pin in this mode is reported
the same way as with INPUT, but the pin voltage
is gently "pulled down" towards 0v. This means
the state will be low unless an external device
is specifically pulling the pin up to 3.3v, in
which case the "gentle" pull down will not
affect the state of the input. */
INPUT_FLOATING, /**< Synonym for INPUT. */
PWM, /**< This is a special mode for when the pin will be used for
PWM output (a special case of digital output). */
PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating
cycles of LOW and HIGH, the voltage on the pin
consists of alternating cycles of LOW and
floating (disconnected). */
} WiringPinMode;
/**
* Configure behavior of a GPIO pin.
*
* @param pin Number of pin to configure.
* @param mode Mode corresponding to desired pin behavior.
* @see WiringPinMode
*/
void pinMode(uint8 pin, WiringPinMode mode);
#define HIGH 0x1
#define LOW 0x0
/**
* Writes a (digital) value to a pin. The pin must have its
* mode set to OUTPUT or OUTPUT_OPEN_DRAIN.
*
* @param pin Pin to write to.
* @param value Either LOW (write a 0) or HIGH (write a 1).
* @see pinMode()
*/
void digitalWrite(uint8 pin, uint8 value);
/**
* Read a digital value from a pin. The pin must have its mode set to
* one of INPUT, INPUT_PULLUP, and INPUT_PULLDOWN.
*
* @param pin Pin to read from.
* @return LOW or HIGH.
* @see pinMode()
*/
uint32 digitalRead(uint8 pin);
/**
* Read an analog value from pin. This function blocks during ADC
* conversion, and has 12 bits of resolution. The pin must have its
* mode set to INPUT_ANALOG.
*
* @param pin Pin to read from.
* @return Converted voltage, in the range 0--4095, (i.e. a 12-bit ADC
* conversion).
* @see pinMode()
*/
uint16 analogRead(uint8 pin);
#if FALSE
// Roger Clark. Deprecated these functions as they are not part of the standard Arduino API
/**
* Toggles the digital value at the given pin.
*
* The pin must have its mode set to OUTPUT.
*
* @param pin the pin to toggle. If the pin is HIGH, set it LOW. If
* it is LOW, set it HIGH.
*
* @see pinMode()
*/
void togglePin(uint8 pin);
/**
* Toggle the LED.
*
* If the LED is on, turn it off. If it is off, turn it on.
*
* The LED must its mode set to OUTPUT. This can be accomplished
* portably over all LeafLabs boards by calling pinMode(BOARD_LED_PIN,
* OUTPUT) before calling this function.
*
* @see pinMode()
*/
static inline void toggleLED() {
togglePin(BOARD_LED_PIN);
}
/**
* If the button is currently pressed, waits until the button is no
* longer being pressed, and returns true. Otherwise, returns false.
*
* The button pin must have its mode set to INPUT. This can be
* accomplished portably over all LeafLabs boards by calling
* pinMode(BOARD_BUTTON_PIN, INPUT).
*
* @see pinMode()
*/
uint8 isButtonPressed(uint8 pin=BOARD_BUTTON_PIN,
uint32 pressedLevel=BOARD_BUTTON_PRESSED_LEVEL);
/**
* Wait until the button is pressed and released, timing out if no
* press occurs.
*
* The button pin must have its mode set to INPUT. This can be
* accomplished portably over all LeafLabs boards by calling
* pinMode(BOARD_BUTTON_PIN, INPUT).
*
* @param timeout_millis Number of milliseconds to wait until the
* button is pressed. If timeout_millis is left out (or 0), wait
* forever.
*
* @return true, if the button was pressed; false, if the timeout was
* reached.
*
* @see pinMode()
*/
uint8 waitForButtonPress(uint32 timeout_millis=0);
#endif
/**
* Shift out a byte of data, one bit at a time.
*
* This function starts at either the most significant or least
* significant bit in a byte value, and shifts out each byte in order
* onto a data pin. After each bit is written to the data pin, a
* separate clock pin is pulsed to indicate that the new bit is
* available.
*
* @param dataPin Pin to shift data out on
* @param clockPin Pin to pulse after each bit is shifted out
* @param bitOrder Either MSBFIRST (big-endian) or LSBFIRST (little-endian).
* @param value Value to shift out
*/
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value);
#endif

View File

@ -1,94 +1,97 @@
/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
* Copyright (c) 2012 LeafLabs, LLC.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
/*
* Arduino-compatible digital I/O implementation.
*/
#include "io.h"
#include <libmaple/gpio.h>
#include <libmaple/timer.h>
#include "wirish_time.h"
#include "boards.h"
uint32 digitalRead(uint8 pin) {
if (pin >= BOARD_NR_GPIO_PINS) {
return 0;
}
return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit) ?
HIGH : LOW;
}
void digitalWrite(uint8 pin, uint8 val) {
if (pin >= BOARD_NR_GPIO_PINS) {
return;
}
gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);
}
void togglePin(uint8 pin) {
if (pin >= BOARD_NR_GPIO_PINS) {
return;
}
gpio_toggle_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit);
}
#define BUTTON_DEBOUNCE_DELAY 1
uint8 isButtonPressed(uint8 pin, uint32 pressedLevel) {
if (digitalRead(pin) == pressedLevel) {
delay(BUTTON_DEBOUNCE_DELAY);
while (digitalRead(pin) == pressedLevel)
;
return true;
}
return false;
}
uint8 waitForButtonPress(uint32 timeout) {
uint32 start = millis();
uint32 time;
if (timeout == 0) {
while (!isButtonPressed())
;
return true;
}
do {
time = millis();
/* properly handle wrap-around */
if ((start > time && time + (0xffffffffU - start) > timeout) ||
time - start > timeout) {
return false;
}
} while (!isButtonPressed());
return true;
}
/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 Perry Hung.
* Copyright (c) 2012 LeafLabs, LLC.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
/*
* Arduino-compatible digital I/O implementation.
*/
#include "io.h"
#include <libmaple/gpio.h>
#include <libmaple/timer.h>
#include "wirish_time.h"
#include "boards.h"
uint32 digitalRead(uint8 pin) {
if (pin >= BOARD_NR_GPIO_PINS) {
return 0;
}
return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit) ?
HIGH : LOW;
}
void digitalWrite(uint8 pin, uint8 val) {
if (pin >= BOARD_NR_GPIO_PINS) {
return;
}
gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);
}
#if FALSE
// Roger Clark. Deprecated these functions as they are not part of the standard Arduino API
void togglePin(uint8 pin) {
if (pin >= BOARD_NR_GPIO_PINS) {
return;
}
gpio_toggle_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit);
}
#define BUTTON_DEBOUNCE_DELAY 1
uint8 isButtonPressed(uint8 pin, uint32 pressedLevel) {
if (digitalRead(pin) == pressedLevel) {
delay(BUTTON_DEBOUNCE_DELAY);
while (digitalRead(pin) == pressedLevel)
;
return true;
}
return false;
}
uint8 waitForButtonPress(uint32 timeout) {
uint32 start = millis();
uint32 time;
if (timeout == 0) {
while (!isButtonPressed())
;
return true;
}
do {
time = millis();
/* properly handle wrap-around */
if ((start > time && time + (0xffffffffU - start) > timeout) ||
time - start > timeout) {
return false;
}
} while (!isButtonPressed());
return true;
}
#endif

View File

@ -1,37 +1,37 @@
/******************************************************************************
* The MIT License
*
* Copyright (c) 2012 LeafLabs, LLC.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
#include "wirish.h"
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value) {
digitalWrite(clockPin, LOW);
for (int i = 0; i < 8; i++) {
int bit = bitOrder == LSBFIRST ? i : (7 - i);
digitalWrite(dataPin, (value >> bit) & 0x1);
togglePin(clockPin);
togglePin(clockPin);
}
}
/******************************************************************************
* The MIT License
*
* Copyright (c) 2012 LeafLabs, LLC.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/
#include "wirish.h"
void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value) {
digitalWrite(clockPin, LOW);
for (int i = 0; i < 8; i++) {
int bit = bitOrder == LSBFIRST ? i : (7 - i);
digitalWrite(dataPin, (value >> bit) & 0x1);
gpio_toggle_bit(PIN_MAP[clockPin].gpio_device, PIN_MAP[clockPin].gpio_bit);// togglePin(clockPin);
gpio_toggle_bit(PIN_MAP[clockPin].gpio_device, PIN_MAP[clockPin].gpio_bit);// togglePin(clockPin);
}
}

View File

@ -1,336 +1,336 @@
#include "LiquidCrystal.h"
#include <stdio.h>
#include <string.h>
#include <WProgram.h>
// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
// DL = 1; 8-bit interface data
// N = 0; 1-line display
// F = 0; 5x8 dot character font
// 3. Display on/off control:
// D = 0; Display off
// C = 0; Cursor off
// B = 0; Blinking off
// 4. Entry mode set:
// I/D = 1; Increment by 1
// S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).
// This library has been modified to be compatible with the LeafLabs Maple;
// very conservative timing is used due to problems with delayMicroseconds()
// that should be fixed in the 0.0.7 release of the libmaple. [bnewbold]
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3)
{
init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3)
{
init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
}
void LiquidCrystal::init(uint8 fourbitmode, uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
_rs_pin = rs;
_rw_pin = rw;
_enable_pin = enable;
_data_pins[0] = d0;
_data_pins[1] = d1;
_data_pins[2] = d2;
_data_pins[3] = d3;
_data_pins[4] = d4;
_data_pins[5] = d5;
_data_pins[6] = d6;
_data_pins[7] = d7;
displaymode=fourbitmode;
if (fourbitmode)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
else
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
// TODO: bnewbold, re-enable this?
// begin(16, 1);
}
void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) {
for (int i = 0; i < 8 - displaymode * 4; i++) {
//for (int i = 0; i <4; i++) {
pinMode(_data_pins[i], OUTPUT);
}
pinMode(_rs_pin, OUTPUT);
// we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
if (_rw_pin != 255) {
pinMode(_rw_pin, OUTPUT);
}
pinMode(_enable_pin, OUTPUT);
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;
// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
_displayfunction |= LCD_5x10DOTS;
}
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! according to
// datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so
// we'll wait 50
delay(50); // Maple mod
//delayMicroseconds(50000);
// Now we pull both RS and R/W low to begin commands
digitalWrite(_rs_pin, LOW);
digitalWrite(_enable_pin, LOW);
if (_rw_pin != 255) {
digitalWrite(_rw_pin, LOW);
}
//put the LCD into 4 bit or 8 bit mode
if (! (_displayfunction & LCD_8BITMODE)) {
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
write4bits(0x03);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03);
delay(1); // Maple mod
//delayMicroseconds(150);
// finally, set to 8-bit interface
write4bits(0x02);
} else {
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23
// Send function set command sequence
command(LCD_FUNCTIONSET | _displayfunction);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait more than 4.1ms
// second try
command(LCD_FUNCTIONSET | _displayfunction);
delay(1); // Maple mod
//delayMicroseconds(150);
// third go
command(LCD_FUNCTIONSET | _displayfunction);
}
// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
display();
// clear it off
clear();
// Initialize to default text direction (for romance languages)
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);
}
/********** high level commands, for the user! */
void LiquidCrystal::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delay(2); // Maple mod
//delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delay(2); // Maple mod
//delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::setCursor(uint8 col, uint8 row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
// Turn the display on/off (quickly)
void LiquidCrystal::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void LiquidCrystal::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void LiquidCrystal::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void LiquidCrystal::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void LiquidCrystal::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void LiquidCrystal::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void LiquidCrystal::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void LiquidCrystal::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal::createChar(uint8 location, uint8 charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
write(charmap[i]);
}
}
/*********** mid level commands, for sending data/cmds */
inline void LiquidCrystal::command(uint8 value) {
send(value, LOW);
}
inline size_t LiquidCrystal::write(uint8 value) {
send(value, HIGH);
return 1;
}
/************ low level data pushing commands **********/
// write either command or data, with automatic 4/8-bit selection
void LiquidCrystal::send(uint8 value, uint8 mode) {
digitalWrite(_rs_pin, mode);
// if there is a RW pin indicated, set it low to Write
if (_rw_pin != 255) {
digitalWrite(_rw_pin, LOW);
}
if (_displayfunction & LCD_8BITMODE) {
write8bits(value);
} else {
write4bits(value>>4);
write4bits(value);
}
}
void LiquidCrystal::pulseEnable(void) {
// _enable_pin should already be LOW (unless someone else messed
// with it), so don't sit around waiting for long.
digitalWrite(_enable_pin, LOW);
delayMicroseconds(1);
// Enable pulse must be > 450 ns. Value chosen here according to
// the following threads:
// http://forums.leaflabs.com/topic.php?id=640
// http://forums.leaflabs.com/topic.php?id=512
togglePin(_enable_pin);
delayMicroseconds(1);
togglePin(_enable_pin);
// Commands needs > 37us to settle.
delayMicroseconds(42);
}
void LiquidCrystal::write4bits(uint8 value) {
for (int i = 0; i < 4; i++) {
digitalWrite(_data_pins[i], (value >> i) & 0x01);
}
pulseEnable();
}
void LiquidCrystal::write8bits(uint8 value) {
for (int i = 0; i < 8; i++) {
digitalWrite(_data_pins[i], (value >> i) & 0x01);
}
pulseEnable();
}
#include "LiquidCrystal.h"
#include <stdio.h>
#include <string.h>
#include <WProgram.h>
// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
// DL = 1; 8-bit interface data
// N = 0; 1-line display
// F = 0; 5x8 dot character font
// 3. Display on/off control:
// D = 0; Display off
// C = 0; Cursor off
// B = 0; Blinking off
// 4. Entry mode set:
// I/D = 1; Increment by 1
// S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).
// This library has been modified to be compatible with the LeafLabs Maple;
// very conservative timing is used due to problems with delayMicroseconds()
// that should be fixed in the 0.0.7 release of the libmaple. [bnewbold]
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3)
{
init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
}
LiquidCrystal::LiquidCrystal(uint8 rs, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3)
{
init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
}
void LiquidCrystal::init(uint8 fourbitmode, uint8 rs, uint8 rw, uint8 enable,
uint8 d0, uint8 d1, uint8 d2, uint8 d3,
uint8 d4, uint8 d5, uint8 d6, uint8 d7)
{
_rs_pin = rs;
_rw_pin = rw;
_enable_pin = enable;
_data_pins[0] = d0;
_data_pins[1] = d1;
_data_pins[2] = d2;
_data_pins[3] = d3;
_data_pins[4] = d4;
_data_pins[5] = d5;
_data_pins[6] = d6;
_data_pins[7] = d7;
displaymode=fourbitmode;
if (fourbitmode)
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
else
_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
// TODO: bnewbold, re-enable this?
// begin(16, 1);
}
void LiquidCrystal::begin(uint8 cols, uint8 lines, uint8 dotsize) {
for (int i = 0; i < 8 - displaymode * 4; i++) {
//for (int i = 0; i <4; i++) {
pinMode(_data_pins[i], OUTPUT);
}
pinMode(_rs_pin, OUTPUT);
// we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
if (_rw_pin != 255) {
pinMode(_rw_pin, OUTPUT);
}
pinMode(_enable_pin, OUTPUT);
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;
// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
_displayfunction |= LCD_5x10DOTS;
}
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! according to
// datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so
// we'll wait 50
delay(50); // Maple mod
//delayMicroseconds(50000);
// Now we pull both RS and R/W low to begin commands
digitalWrite(_rs_pin, LOW);
digitalWrite(_enable_pin, LOW);
if (_rw_pin != 255) {
digitalWrite(_rw_pin, LOW);
}
//put the LCD into 4 bit or 8 bit mode
if (! (_displayfunction & LCD_8BITMODE)) {
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46
// we start in 8bit mode, try to set 4 bit mode
write4bits(0x03);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait min 4.1ms
// second try
write4bits(0x03);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait min 4.1ms
// third go!
write4bits(0x03);
delay(1); // Maple mod
//delayMicroseconds(150);
// finally, set to 8-bit interface
write4bits(0x02);
} else {
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23
// Send function set command sequence
command(LCD_FUNCTIONSET | _displayfunction);
delay(5); // Maple mod
//delayMicroseconds(4500); // wait more than 4.1ms
// second try
command(LCD_FUNCTIONSET | _displayfunction);
delay(1); // Maple mod
//delayMicroseconds(150);
// third go
command(LCD_FUNCTIONSET | _displayfunction);
}
// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
display();
// clear it off
clear();
// Initialize to default text direction (for romance languages)
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);
}
/********** high level commands, for the user! */
void LiquidCrystal::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delay(2); // Maple mod
//delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delay(2); // Maple mod
//delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::setCursor(uint8 col, uint8 row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
// Turn the display on/off (quickly)
void LiquidCrystal::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void LiquidCrystal::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void LiquidCrystal::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void LiquidCrystal::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
// This is for text that flows Left to Right
void LiquidCrystal::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void LiquidCrystal::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void LiquidCrystal::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void LiquidCrystal::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal::createChar(uint8 location, uint8 charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
write(charmap[i]);
}
}
/*********** mid level commands, for sending data/cmds */
inline void LiquidCrystal::command(uint8 value) {
send(value, LOW);
}
inline size_t LiquidCrystal::write(uint8 value) {
send(value, HIGH);
return 1;
}
/************ low level data pushing commands **********/
// write either command or data, with automatic 4/8-bit selection
void LiquidCrystal::send(uint8 value, uint8 mode) {
digitalWrite(_rs_pin, mode);
// if there is a RW pin indicated, set it low to Write
if (_rw_pin != 255) {
digitalWrite(_rw_pin, LOW);
}
if (_displayfunction & LCD_8BITMODE) {
write8bits(value);
} else {
write4bits(value>>4);
write4bits(value);
}
}
void LiquidCrystal::pulseEnable(void) {
// _enable_pin should already be LOW (unless someone else messed
// with it), so don't sit around waiting for long.
digitalWrite(_enable_pin, LOW);
delayMicroseconds(1);
// Enable pulse must be > 450 ns. Value chosen here according to
// the following threads:
// http://forums.leaflabs.com/topic.php?id=640
// http://forums.leaflabs.com/topic.php?id=512
gpio_toggle_bit(PIN_MAP[_enable_pin].gpio_device, PIN_MAP[_enable_pin].gpio_bit);// togglePin(_enable_pin);
delayMicroseconds(1);
gpio_toggle_bit(PIN_MAP[_enable_pin].gpio_device, PIN_MAP[_enable_pin].gpio_bit);// togglePin(_enable_pin);
// Commands needs > 37us to settle.
delayMicroseconds(42);
}
void LiquidCrystal::write4bits(uint8 value) {
for (int i = 0; i < 4; i++) {
digitalWrite(_data_pins[i], (value >> i) & 0x01);
}
pulseEnable();
}
void LiquidCrystal::write8bits(uint8 value) {
for (int i = 0; i < 8; i++) {
digitalWrite(_data_pins[i], (value >> i) & 0x01);
}
pulseEnable();
}

View File

@ -14,6 +14,6 @@ void setup() {
}
void loop() {
toggleLED(); // Turn the LED from off to on, or on to off
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(1000); // Wait for 1 second (1000 milliseconds)
}

View File

@ -1,37 +1,37 @@
/*
Blink without delay
Turns on and off the built-in light emitting diode (LED), without
using the delay() function. This means that other code can run at
the same time without being interrupted by the LED code.
created 2005
by David A. Mellis
modified 17 Jun 2009
by Tom Igoe
modified for Maple 27 May 2011
by Marti Bolivar
*/
// Variables:
int previousMillis = 0; // will store the last time the LED was updated
int interval = 1000; // interval at which to blink (in milliseconds)
void setup() {
// Set up the built-in LED pin as output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
// Check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time we blinked
// the LED is bigger than the interval at which we want to blink
// the LED.
if (millis() - previousMillis > interval) {
// Save the last time you blinked the LED
previousMillis = millis();
// If the LED is off, turn it on, and vice-versa:
toggleLED();
}
}
/*
Blink without delay
Turns on and off the built-in light emitting diode (LED), without
using the delay() function. This means that other code can run at
the same time without being interrupted by the LED code.
created 2005
by David A. Mellis
modified 17 Jun 2009
by Tom Igoe
modified for Maple 27 May 2011
by Marti Bolivar
*/
// Variables:
int previousMillis = 0; // will store the last time the LED was updated
int interval = 1000; // interval at which to blink (in milliseconds)
void setup() {
// Set up the built-in LED pin as output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
// Check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time we blinked
// the LED is bigger than the interval at which we want to blink
// the LED.
if (millis() - previousMillis > interval) {
// Save the last time you blinked the LED
previousMillis = millis();
// If the LED is off, turn it on, and vice-versa:
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
}
}

View File

@ -15,10 +15,22 @@ void setup() {
pinMode(BOARD_BUTTON_PIN, INPUT);
}
#define BUTTON_DEBOUNCE_DELAY 1
uint8 isButtonPressed(uint8 pin=BOARD_BUTTON_PIN,
uint32 pressedLevel=BOARD_BUTTON_PRESSED_LEVEL) {
if (digitalRead(pin) == pressedLevel) {
delay(BUTTON_DEBOUNCE_DELAY);
while (digitalRead(pin) == pressedLevel)
;
return true;
}
return false;
}
void loop() {
// Check if the button is pressed.
if (isButtonPressed()) {
// If so, turn the LED from on to off, or from off to on:
toggleLED();
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,66 +1,66 @@
/*
Slave mode for Quality Assurance test
Used as follows:
1) Connect all non-used pins on the test board to their
corresponding pins on a board running InteractiveTest.
2) Connect a serial monitor to the InteractiveTest board and
enter "+" (a plus sign, without the quotes).
This program pulses each unused pin in order, starting from pin 0.
The InteractiveTest "+" command detects these pulses, and makes
sure that no other pins change state at the same time.
If you hold the button on the board running this program, the
pulses run slower.
Useful as a simple test of functionality for GPIO pins.
*/
#define INTER_TOGGLE_DELAY_NORMAL 5
#define INTER_TOGGLE_DELAY_SLOW 80
void interToggleDelay(void);
void setup() {
pinMode(BOARD_LED_PIN, OUTPUT);
pinMode(BOARD_BUTTON_PIN, INPUT);
// All unused pins start out low.
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i))
continue;
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}
void loop() {
toggleLED();
delay(100);
toggleLED();
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i))
continue;
// Bring just this pin high.
digitalWrite(i, HIGH);
// Give the master time to detect if any other pins also went high.
interToggleDelay();
// Bring this pin back low again; all pins should now be low.
digitalWrite(i, LOW);
// Give the master time to detect if any pins are still high.
interToggleDelay();
}
}
void interToggleDelay(void) {
if (digitalRead(BOARD_BUTTON_PIN)) { // don't pay the debouncing time
delay(INTER_TOGGLE_DELAY_SLOW);
} else {
delay(INTER_TOGGLE_DELAY_NORMAL);
}
}
/*
Slave mode for Quality Assurance test
Used as follows:
1) Connect all non-used pins on the test board to their
corresponding pins on a board running InteractiveTest.
2) Connect a serial monitor to the InteractiveTest board and
enter "+" (a plus sign, without the quotes).
This program pulses each unused pin in order, starting from pin 0.
The InteractiveTest "+" command detects these pulses, and makes
sure that no other pins change state at the same time.
If you hold the button on the board running this program, the
pulses run slower.
Useful as a simple test of functionality for GPIO pins.
*/
#define INTER_TOGGLE_DELAY_NORMAL 5
#define INTER_TOGGLE_DELAY_SLOW 80
void interToggleDelay(void);
void setup() {
pinMode(BOARD_LED_PIN, OUTPUT);
pinMode(BOARD_BUTTON_PIN, INPUT);
// All unused pins start out low.
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i))
continue;
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}
void loop() {
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100);
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i))
continue;
// Bring just this pin high.
digitalWrite(i, HIGH);
// Give the master time to detect if any other pins also went high.
interToggleDelay();
// Bring this pin back low again; all pins should now be low.
digitalWrite(i, LOW);
// Give the master time to detect if any pins are still high.
interToggleDelay();
}
}
void interToggleDelay(void) {
if (digitalRead(BOARD_BUTTON_PIN)) { // don't pay the debouncing time
delay(INTER_TOGGLE_DELAY_SLOW);
} else {
delay(INTER_TOGGLE_DELAY_NORMAL);
}
}

View File

@ -1,17 +1,17 @@
/*
Blink: Turns on the built-in LED on for one second, then off for one second, repeatedly.
Arduino 1.6.0rc1
Sketch uses 11,900 bytes (11%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Ported to Maple from the Arduino example 27 May 2011 By Marti Bolivar
*/
void setup() {
// Set up the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
toggleLED(); // Turn the LED from off to on, or on to off
delay(1000); // Wait for 1 second (1000 milliseconds)
}
/*
Blink: Turns on the built-in LED on for one second, then off for one second, repeatedly.
Arduino 1.6.0rc1
Sketch uses 11,900 bytes (11%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Ported to Maple from the Arduino example 27 May 2011 By Marti Bolivar
*/
void setup() {
// Set up the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(1000); // Wait for 1 second (1000 milliseconds)
}

View File

@ -1,35 +1,35 @@
/*
BlinkNcount for Maple Mini by m. ray burnette
Sketch uses 13,808 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Turns on an LED on for one second, then off for one second, repeatedly.
Counts and displays the count on the attached serial monitor
This example code is in the public domain.
*/
int n = 0;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
// Initialize virtual COM over USB on Maple Mini
Serial.begin(9600); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Blink LED & count Demo");
}
void loop() {
digitalWrite(BOARD_LED_PIN, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(BOARD_LED_PIN, LOW); // set the LED off
Serial.print("Loop #: ");
n++;
Serial.println(n);
delay(500); // wait
}
/*
BlinkNcount for Maple Mini by m. ray burnette
Sketch uses 13,808 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Turns on an LED on for one second, then off for one second, repeatedly.
Counts and displays the count on the attached serial monitor
This example code is in the public domain.
*/
int n = 0;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
// Initialize virtual COM over USB on Maple Mini
Serial.begin(9600); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Blink LED & count Demo");
}
void loop() {
digitalWrite(BOARD_LED_PIN, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(BOARD_LED_PIN, LOW); // set the LED off
Serial.print("Loop #: ");
n++;
Serial.println(n);
delay(500); // wait
}

View File

@ -1,46 +1,46 @@
/*
IntegerInput by m. Ray Burnette - PUBLIC DOMAIN EXAMPLE
Maple Mini: Compiled under Arduino 1.6.0rc1
Sketch uses 15,624 bytes (14%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,704 bytes of dynamic memory.
*/
#define BAUD 9600
#define timeoutPeriod 2147483647 // Long time... about 25 days
int a;
int b;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
Serial.setTimeout(timeoutPeriod); // default is 1 second
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
}
void loop()
{
Serial.println("Enter first integer: ");
a = Serial.parseInt();
Serial.print("a = ");
Serial.println(a);
Serial.println("Enter second integer: ");
b = Serial.parseInt();
Serial.print("b = ");
Serial.println(b);
Serial.print("Sum a + b =");
Serial.println( a + b);
Serial.print("Dif a - b =");
Serial.println(a - b);
}
/*
IntegerInput by m. Ray Burnette - PUBLIC DOMAIN EXAMPLE
Maple Mini: Compiled under Arduino 1.6.0rc1
Sketch uses 15,624 bytes (14%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,704 bytes of dynamic memory.
*/
#define BAUD 9600
#define timeoutPeriod 2147483647 // Long time... about 25 days
int a;
int b;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
Serial.setTimeout(timeoutPeriod); // default is 1 second
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
}
void loop()
{
Serial.println("Enter first integer: ");
a = Serial.parseInt();
Serial.print("a = ");
Serial.println(a);
Serial.println("Enter second integer: ");
b = Serial.parseInt();
Serial.print("b = ");
Serial.println(b);
Serial.print("Sum a + b =");
Serial.println( a + b);
Serial.print("Dif a - b =");
Serial.println(a - b);
}

View File

@ -1,50 +1,50 @@
/*
IntegerInput_FloatOutput by m. Ray Burnette - PUBLIC DOMAIN EXAMPLE
Maple Mini: Compiled under Arduino 1.6.0rc1
Sketch uses 19,868 bytes (18%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,704 bytes of dynamic memory.
*/
#define BAUD 9600
#define timeoutPeriod 2147483647 // Long var... about 25 days
float a;
float b;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
Serial.setTimeout(timeoutPeriod); // default is 1 second
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Integer Input - Floating Output");
Serial.println("You may wish to try 355 and 113 (Pi)");
}
void loop()
{
Serial.println("Enter first integer: ");
a = Serial.parseInt();
Serial.print("a = ");
Serial.println(a);
Serial.println("Enter second integer: ");
b = Serial.parseInt();
Serial.print("b = ");
Serial.println(b);
a = a / b;
Serial.print( "a/b = ");
Serial.println(a);
Serial.println();
}
/*
IntegerInput_FloatOutput by m. Ray Burnette - PUBLIC DOMAIN EXAMPLE
Maple Mini: Compiled under Arduino 1.6.0rc1
Sketch uses 19,868 bytes (18%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,704 bytes of dynamic memory.
*/
#define BAUD 9600
#define timeoutPeriod 2147483647 // Long var... about 25 days
float a;
float b;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
Serial.setTimeout(timeoutPeriod); // default is 1 second
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Integer Input - Floating Output");
Serial.println("You may wish to try 355 and 113 (Pi)");
}
void loop()
{
Serial.println("Enter first integer: ");
a = Serial.parseInt();
Serial.print("a = ");
Serial.println(a);
Serial.println("Enter second integer: ");
b = Serial.parseInt();
Serial.print("b = ");
Serial.println(b);
a = a / b;
Serial.print( "a/b = ");
Serial.println(a);
Serial.println();
}

View File

@ -1,80 +1,80 @@
/*
Re: http://leaflabs.com/docs/hardware
Arduino 1.6.0rc1 modifications by m. ray burnette
Sketch uses 31,608 bytes (29%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,752 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
//#include <stdio.h>
#include <libmaple/adc.h>
#define LED_PIN BOARD_LED_PIN
#define A_RANDOM_ANALOG_PIN 15
void setup_temperature_sensor() {
adc_reg_map *regs = ADC1->regs;
// 3. Set the TSVREFE bit in the ADC control register 2 (ADC_CR2) to wake up the
// temperature sensor from power down mode. Do this first 'cause according to
// the Datasheet section 5.3.21 it takes from 4 to 10 uS to power up the sensor.
regs->CR2 |= ADC_CR2_TSEREFE;
// 2. Select a sample time of 17.1 μs
// set channel 16 sample time to 239.5 cycles
// 239.5 cycles of the ADC clock (72MHz/6=12MHz) is over 17.1us (about 20us), but no smaller
// sample time exceeds 17.1us.
regs->SMPR1 = (0b111 << (3*6)); // set channel 16, the temp. sensor
}
void setup(void)
{
// Set up the LED to blink
pinMode(LED_PIN, OUTPUT);
// set up an analog input. We want to test and make sure other analog reads don't screw this up.
pinMode(A_RANDOM_ANALOG_PIN, INPUT_ANALOG);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
// init tem psensor
setup_temperature_sensor();
// announce start up
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS()))
Serial.println("Temp mon startup");
}
//
// once per second perform a standard analog read and read the temperature sensor
// the analog read is to test whether our messing with the temp sensor will screw up analog reads
// or visa versa.
// Also compute and display the time each operation takes.
//
void loop(void)
{
uint16 vsense, alogpin;
uint32 t1, t2, t3;
char buf[64];
t1 = micros();
alogpin = analogRead(A_RANDOM_ANALOG_PIN);
t2 = micros();
vsense = adc_read(ADC1, 16);
t3 = micros();
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())) {
sprintf(buf,"%04x %08x %04x %08x" , vsense, t3-t2, alogpin, t2-t1);
Serial.println(buf);
}
toggleLED();
delay(1000);
}
/*
Re: http://leaflabs.com/docs/hardware
Arduino 1.6.0rc1 modifications by m. ray burnette
Sketch uses 31,608 bytes (29%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,752 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
//#include <stdio.h>
#include <libmaple/adc.h>
#define LED_PIN BOARD_LED_PIN
#define A_RANDOM_ANALOG_PIN 15
void setup_temperature_sensor() {
adc_reg_map *regs = ADC1->regs;
// 3. Set the TSVREFE bit in the ADC control register 2 (ADC_CR2) to wake up the
// temperature sensor from power down mode. Do this first 'cause according to
// the Datasheet section 5.3.21 it takes from 4 to 10 uS to power up the sensor.
regs->CR2 |= ADC_CR2_TSEREFE;
// 2. Select a sample time of 17.1 μs
// set channel 16 sample time to 239.5 cycles
// 239.5 cycles of the ADC clock (72MHz/6=12MHz) is over 17.1us (about 20us), but no smaller
// sample time exceeds 17.1us.
regs->SMPR1 = (0b111 << (3*6)); // set channel 16, the temp. sensor
}
void setup(void)
{
// Set up the LED to blink
pinMode(LED_PIN, OUTPUT);
// set up an analog input. We want to test and make sure other analog reads don't screw this up.
pinMode(A_RANDOM_ANALOG_PIN, INPUT_ANALOG);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
// init tem psensor
setup_temperature_sensor();
// announce start up
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS()))
Serial.println("Temp mon startup");
}
//
// once per second perform a standard analog read and read the temperature sensor
// the analog read is to test whether our messing with the temp sensor will screw up analog reads
// or visa versa.
// Also compute and display the time each operation takes.
//
void loop(void)
{
uint16 vsense, alogpin;
uint32 t1, t2, t3;
char buf[64];
t1 = micros();
alogpin = analogRead(A_RANDOM_ANALOG_PIN);
t2 = micros();
vsense = adc_read(ADC1, 16);
t3 = micros();
if(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())) {
sprintf(buf,"%04x %08x %04x %08x" , vsense, t3-t2, alogpin, t2-t1);
Serial.println(buf);
}
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(1000);
}

View File

@ -1,69 +1,69 @@
/*
PrimeNos: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 13,644 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,656 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
// just add more primes to the prime table for larger search
// byte data type to save memory - use a larger datatype with prime table entries above 255 :)
byte primes[]={
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
102, 107, 109, 113, 127, 131, 137 , 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
199, 211, 223, 227, 229, 233, 239, 241, 251 };
// if you change the datatype of primes array to int, change next line to
// "const int TopPrimeIndex = (sizeof(primes)/2) - 1;"
const unsigned int TopPrimeIndex = sizeof(primes) - 1;
const unsigned long TopPrimeSquared = (long)primes[TopPrimeIndex] * (long)primes[TopPrimeIndex];
int primeFlag;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Prime Number Generator");
Serial.print("Number of primes in prime table = ");
Serial.println(TopPrimeIndex);
Serial.println();
Serial.print("Last prime in table = ");
Serial.println((unsigned int)primes[TopPrimeIndex]);
Serial.println();
Serial.print("Calculating primes through ");
Serial.println(TopPrimeSquared);
Serial.println();
}
void loop() // run over and over again
{
for (long x = 1; x < TopPrimeSquared; x+=2){ // skips even numbers, including 2, which is prime, but it makes algorithm tad faster
for (long j=0; j < TopPrimeIndex; j++){
primeFlag = true;
if (x == primes[j]) break;
if (x % primes[j] == 0){ // if the test number modolo (next number from prime table) == 0
primeFlag = false; // then test number is not prime, bailout and check the next number
break;
}
}
if (primeFlag == true){ // found a prime - print it
Serial.println(x);
}
}
}
/*
PrimeNos: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 13,644 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,656 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
// just add more primes to the prime table for larger search
// byte data type to save memory - use a larger datatype with prime table entries above 255 :)
byte primes[]={
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
102, 107, 109, 113, 127, 131, 137 , 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
199, 211, 223, 227, 229, 233, 239, 241, 251 };
// if you change the datatype of primes array to int, change next line to
// "const int TopPrimeIndex = (sizeof(primes)/2) - 1;"
const unsigned int TopPrimeIndex = sizeof(primes) - 1;
const unsigned long TopPrimeSquared = (long)primes[TopPrimeIndex] * (long)primes[TopPrimeIndex];
int primeFlag;
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Prime Number Generator");
Serial.print("Number of primes in prime table = ");
Serial.println(TopPrimeIndex);
Serial.println();
Serial.print("Last prime in table = ");
Serial.println((unsigned int)primes[TopPrimeIndex]);
Serial.println();
Serial.print("Calculating primes through ");
Serial.println(TopPrimeSquared);
Serial.println();
}
void loop() // run over and over again
{
for (long x = 1; x < TopPrimeSquared; x+=2){ // skips even numbers, including 2, which is prime, but it makes algorithm tad faster
for (long j=0; j < TopPrimeIndex; j++){
primeFlag = true;
if (x == primes[j]) break;
if (x % primes[j] == 0){ // if the test number modolo (next number from prime table) == 0
primeFlag = false; // then test number is not prime, bailout and check the next number
break;
}
}
if (primeFlag == true){ // found a prime - print it
Serial.println(x);
}
}
}

View File

@ -1,41 +1,41 @@
/*
PrimeNos3: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 16,616 bytes (15%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,624 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
const int SHOW_EVERY = 500; // how often to echo a prime to the serial port
int candidate;
int found = 5; // Number we found
int count = found - 1;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Prime Number Generator V2");
}
void loop() {
Serial.println("Prime numbers between 1 and 99999999 are:");
Serial.println("2 \t");
for (int i=3; i<99999999;i+=2) {
// This loop stops either when j*j>i or when i is divisible by j.
// The first condition means prime, the second, not prime.
int j=3;
for(;j*j<=i && i%j!=0; j+=2); // No loop body
if (j*j>i) Serial.print(i);Serial.print( "\t");
}
Serial.println("\r\n");
}
/*
PrimeNos3: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 16,616 bytes (15%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,624 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
const int SHOW_EVERY = 500; // how often to echo a prime to the serial port
int candidate;
int found = 5; // Number we found
int count = found - 1;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Prime Number Generator V2");
}
void loop() {
Serial.println("Prime numbers between 1 and 99999999 are:");
Serial.println("2 \t");
for (int i=3; i<99999999;i+=2) {
// This loop stops either when j*j>i or when i is divisible by j.
// The first condition means prime, the second, not prime.
int j=3;
for(;j*j<=i && i%j!=0; j+=2); // No loop body
if (j*j>i) Serial.print(i);Serial.print( "\t");
}
Serial.println("\r\n");
}

View File

@ -1,41 +1,41 @@
/*
PrimeNos3: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 13,420 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,600 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
const int SHOW_EVERY = 500; // how often to echo a prime to the serial port
int candidate;
int found = 5; // Number we found
int count = found - 1;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Prime Number Generator V2");
}
void loop() {
Serial.println("Prime numbers between 1 and 99999999 are:");
Serial.println("2 \t");
for (int i=3; i<99999999;i+=2) {
// This loop stops either when j*j>i or when i is divisible by j.
// The first condition means prime, the second, not prime.
int j=3;
for(;j*j<=i && i%j!=0; j+=2); // No loop body
if (j*j>i) Serial.print(i);Serial.print( "\n\r");
}
Serial.println("\r\n");
}
/*
PrimeNos3: by Nick Gammon
Maple Mini port m. ray burnette: Compiled under Arduino 1.6.0rc1
Sketch uses 13,420 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,600 bytes of dynamic memory.
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
const int SHOW_EVERY = 500; // how often to echo a prime to the serial port
int candidate;
int found = 5; // Number we found
int count = found - 1;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Prime Number Generator V2");
}
void loop() {
Serial.println("Prime numbers between 1 and 99999999 are:");
Serial.println("2 \t");
for (int i=3; i<99999999;i+=2) {
// This loop stops either when j*j>i or when i is divisible by j.
// The first condition means prime, the second, not prime.
int j=3;
for(;j*j<=i && i%j!=0; j+=2); // No loop body
if (j*j>i) Serial.print(i);Serial.print( "\n\r");
}
Serial.println("\r\n");
}

View File

@ -1,66 +1,66 @@
/* PRINT_BINARY - Arduino 1.6.0rc1
Adapted to Maple Mini by m. ray burnette
Sketch uses 11,672 bytes (10%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory
Prints a positive integer in binary format with a fixed withdth
copyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Print Binary Format");
}
void loop()
{
while(1)
{
print_binary(1024+256+63, 12);
Serial.println();
delay(1000);
}
}
void print_binary(int v, int num_places)
{
int mask=0, n;
for (n=1; n<=num_places; n++)
{
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
while(num_places)
{
if (v & (0x0001 << num_places-1))
{
Serial.print("1");
}
else
{
Serial.print("0");
}
--num_places;
if(((num_places%4) == 0) && (num_places != 0))
{
Serial.print("_");
}
}
}
/* PRINT_BINARY - Arduino 1.6.0rc1
Adapted to Maple Mini by m. ray burnette
Sketch uses 11,672 bytes (10%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory
Prints a positive integer in binary format with a fixed withdth
copyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup()
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Print Binary Format");
}
void loop()
{
while(1)
{
print_binary(1024+256+63, 12);
Serial.println();
delay(1000);
}
}
void print_binary(int v, int num_places)
{
int mask=0, n;
for (n=1; n<=num_places; n++)
{
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
while(num_places)
{
if (v & (0x0001 << num_places-1))
{
Serial.print("1");
}
else
{
Serial.print("0");
}
--num_places;
if(((num_places%4) == 0) && (num_places != 0))
{
Serial.print("_");
}
}
}

View File

@ -1,84 +1,84 @@
/*
PRINT_FLOAT - Arduino 1.6.0rc1
Sketch uses 15,164 bytes (14%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Adapted to Maple Mini by m. ray burnette
Illustrates how to display floats in the range of -999.999 to 999.999 with a specified
number of digits after the decimal point.
copyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup() // run once, when the sketch starts
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Print Float Format");
}
void loop()
{
while(1)
{
print_float(0.6, 2); // illustrate various test cases
Serial.println();
print_float(1.2, 1);
Serial.println();
print_float(10.27, 2);
Serial.println();
print_float(10.345, 3);
Serial.println();
print_float(107.345, 3);
Serial.println();
delay(1000);
print_float(-0.6, 2);
Serial.println();
print_float(-1.2, 1);
Serial.println();
print_float(-10.27, 2);
Serial.println();
print_float(-10.345, 3);
Serial.println();
print_float(-107.345, 3);
Serial.println();
delay(1000);
}
}
void print_float(float f, int num_digits)
{
int f_int;
int pows_of_ten[4] = {1, 10, 100, 1000};
int multiplier, whole, fract, d, n;
multiplier = pows_of_ten[num_digits];
if (f < 0.0)
{
f = -f;
Serial.print("-");
}
whole = (int) f;
fract = (int) (multiplier * (f - (float)whole));
Serial.print(whole);
Serial.print(".");
for (n=num_digits-1; n>=0; n--) // print each digit with no leading zero suppression
{
d = fract / pows_of_ten[n];
Serial.print(d);
fract = fract % pows_of_ten[n];
}
}
/*
PRINT_FLOAT - Arduino 1.6.0rc1
Sketch uses 15,164 bytes (14%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Adapted to Maple Mini by m. ray burnette
Illustrates how to display floats in the range of -999.999 to 999.999 with a specified
number of digits after the decimal point.
copyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup() // run once, when the sketch starts
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Print Float Format");
}
void loop()
{
while(1)
{
print_float(0.6, 2); // illustrate various test cases
Serial.println();
print_float(1.2, 1);
Serial.println();
print_float(10.27, 2);
Serial.println();
print_float(10.345, 3);
Serial.println();
print_float(107.345, 3);
Serial.println();
delay(1000);
print_float(-0.6, 2);
Serial.println();
print_float(-1.2, 1);
Serial.println();
print_float(-10.27, 2);
Serial.println();
print_float(-10.345, 3);
Serial.println();
print_float(-107.345, 3);
Serial.println();
delay(1000);
}
}
void print_float(float f, int num_digits)
{
int f_int;
int pows_of_ten[4] = {1, 10, 100, 1000};
int multiplier, whole, fract, d, n;
multiplier = pows_of_ten[num_digits];
if (f < 0.0)
{
f = -f;
Serial.print("-");
}
whole = (int) f;
fract = (int) (multiplier * (f - (float)whole));
Serial.print(whole);
Serial.print(".");
for (n=num_digits-1; n>=0; n--) // print each digit with no leading zero suppression
{
d = fract / pows_of_ten[n];
Serial.print(d);
fract = fract % pows_of_ten[n];
}
}

View File

@ -1,61 +1,61 @@
/*
PRINT_HEX - Arduino 1.6.0rc1
Sketch uses 13,336 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Adapted to the Maple Mini by m. ray burnette
Illustrates how to display a hexadecimal number with a fixed width.
opyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup() // run once, when the sketch starts
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Print HEX Format");
}
void loop()
{
while(1)
{
print_hex(1024+256+63, 13);
Serial.println();
delay(1000);
}
}
void print_hex(int v, int num_places)
{
int mask=0, n, num_nibbles, digit;
for (n=1; n<=num_places; n++)
{
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
num_nibbles = num_places / 4;
if ((num_places % 4) != 0)
{
++num_nibbles;
}
do
{
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
Serial.print(digit, HEX);
} while(--num_nibbles);
}
/*
PRINT_HEX - Arduino 1.6.0rc1
Sketch uses 13,336 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,592 bytes of dynamic memory.
Adapted to the Maple Mini by m. ray burnette
Illustrates how to display a hexadecimal number with a fixed width.
opyright, Peter H Anderson, Baltimore, MD, Nov, '07
PUBLIC DOMAIN EXAMPLE
*/
#define BAUD 9600
void setup() // run once, when the sketch starts
{
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UART
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Print HEX Format");
}
void loop()
{
while(1)
{
print_hex(1024+256+63, 13);
Serial.println();
delay(1000);
}
}
void print_hex(int v, int num_places)
{
int mask=0, n, num_nibbles, digit;
for (n=1; n<=num_places; n++)
{
mask = (mask << 1) | 0x0001;
}
v = v & mask; // truncate v to specified number of places
num_nibbles = num_places / 4;
if ((num_places % 4) != 0)
{
++num_nibbles;
}
do
{
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
Serial.print(digit, HEX);
} while(--num_nibbles);
}

View File

@ -1,35 +1,35 @@
// http://arduino.cc/forum/index.php?topic=114035.0 `
/* Sketch uses 13,836 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,696 bytes of dynamic memory.
Read an unknown length string of ASCII characters terminated
with a line feed from the UART
*/
#define BAUD 9600
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UAR
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("Serial Read Until Example:");
Serial.print("Type a few characters & press ENTER\r\n(make certain serial monitor sends CR+LF)");
}
void loop() {
char serialdata[80];
int lf = 10;
Serial.readBytesUntil(lf, serialdata, 80);
Serial.println(serialdata);
}
// http://arduino.cc/forum/index.php?topic=114035.0 `
/* Sketch uses 13,836 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 3,696 bytes of dynamic memory.
Read an unknown length string of ASCII characters terminated
with a line feed from the UART
*/
#define BAUD 9600
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(BAUD); // BAUD has no effect on USB serial: placeholder for physical UAR
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Serial Read Until Example:");
Serial.print("Type a few characters & press ENTER\r\n(make certain serial monitor sends CR+LF)");
}
void loop() {
char serialdata[80];
int lf = 10;
Serial.readBytesUntil(lf, serialdata, 80);
Serial.println(serialdata);
}

View File

@ -1,104 +1,104 @@
/*
USBascii Example for Arduino 1.6.0rc1 on the Maple Mini STM32 platform
Sketch uses 13,572 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,600 bytes of dynamic memory.
Connect to the Maple Serial using the Serial Monitor, then press
any key and hit enter.
Prints out byte values in all possible formats:
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see:
http://www.asciitable.com
http://en.wikipedia.org/wiki/ASCII
No external hardware needed.
created 2006
by Nicholas Zambetti
modified 18 Jan 2009
by Tom Igoe
<http://www.zambetti.com>
Ported to the Maple 27 May 2010
by Bryan Newbold
Minor edits by m. ray burnette for Arduino 1.6.0
PUBLIC DOMAIN EXAMPLE
*/
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(); // USB does not require BAUD
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
Serial.println("ASCII Table ~ Character Map");
Serial.println("Press CR to start the printout");
}
// First visible ASCII character: '!' is number 33:
int thisByte = 33;
int junk = 0;
bool Virgin = true;
// You can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';
void loop() {
Restart:
// Wait for the user to press a key
if (!Virgin) goto NextPhase;
while (!Serial.available())
continue;
while (Serial.available()) {
junk = Serial.read();
}
//continue;
NextPhase:
Virgin = false ;
// Prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!'
Serial.print(thisByte, BYTE);
Serial.print(", dec: ");
// Prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and
// Serial.println(), so no modifier is needed:
Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
// This also works if you uncomment it:
// Serial.print(thisByte, DEC);
Serial.print(", hex: ");
// Prints value as string in hexadecimal (base 16):
Serial.print(thisByte, HEX);
Serial.print(", oct: ");
// Prints value as string in octal (base 8);
Serial.print(thisByte, OCT);
Serial.print(", bin: ");
// Prints value as string in binary (base 2); also prints ending
// line break:
Serial.println(thisByte, BIN);
// If printed last visible character '~' or 126, stop:
if (thisByte == 126) { // You could also use if (thisByte == '~') {
thisByte = 33;
Virgin = true;
Serial.println("==============================");
Serial.println("Press CR to start the printout");
goto Restart ;
}
// Go on to the next character
thisByte++;
}
/*
USBascii Example for Arduino 1.6.0rc1 on the Maple Mini STM32 platform
Sketch uses 13,572 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,600 bytes of dynamic memory.
Connect to the Maple Serial using the Serial Monitor, then press
any key and hit enter.
Prints out byte values in all possible formats:
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see:
http://www.asciitable.com
http://en.wikipedia.org/wiki/ASCII
No external hardware needed.
created 2006
by Nicholas Zambetti
modified 18 Jan 2009
by Tom Igoe
<http://www.zambetti.com>
Ported to the Maple 27 May 2010
by Bryan Newbold
Minor edits by m. ray burnette for Arduino 1.6.0
PUBLIC DOMAIN EXAMPLE
*/
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(); // USB does not require BAUD
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("ASCII Table ~ Character Map");
Serial.println("Press CR to start the printout");
}
// First visible ASCII character: '!' is number 33:
int thisByte = 33;
int junk = 0;
bool Virgin = true;
// You can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';
void loop() {
Restart:
// Wait for the user to press a key
if (!Virgin) goto NextPhase;
while (!Serial.available())
continue;
while (Serial.available()) {
junk = Serial.read();
}
//continue;
NextPhase:
Virgin = false ;
// Prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!'
Serial.print(thisByte, BYTE);
Serial.print(", dec: ");
// Prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and
// Serial.println(), so no modifier is needed:
Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
// This also works if you uncomment it:
// Serial.print(thisByte, DEC);
Serial.print(", hex: ");
// Prints value as string in hexadecimal (base 16):
Serial.print(thisByte, HEX);
Serial.print(", oct: ");
// Prints value as string in octal (base 8);
Serial.print(thisByte, OCT);
Serial.print(", bin: ");
// Prints value as string in binary (base 2); also prints ending
// line break:
Serial.println(thisByte, BIN);
// If printed last visible character '~' or 126, stop:
if (thisByte == 126) { // You could also use if (thisByte == '~') {
thisByte = 33;
Virgin = true;
Serial.println("==============================");
Serial.println("Press CR to start the printout");
goto Restart ;
}
// Go on to the next character
thisByte++;
}

View File

@ -1,41 +1,41 @@
/*
Modified for Arduino from: http://www.cplusplus.com/reference/cstdlib/strtol/
Convert string to long integer: Maple Mini version by m. ray burnette: PUBLIC DOMAIN
Sketch uses 13,924 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,664 bytes of dynamic memory.
Following C++ libs not needed after Arduino 1.0.2
#include <stdio.h>
#include <stdlib.h>
*/
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
char * pEnd;
long int li1, li2, li3, li4;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(9600);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
toggleLED();
delay(100); // fast blink
}
li1 = strtol (szNumbers,&pEnd,10); // BASE 10
li2 = strtol (pEnd,&pEnd,16); // HEX
li3 = strtol (pEnd,&pEnd,2); // Binary
li4 = strtol (pEnd,NULL,0); // Integer constant with prefixed base Octal or Hex
// Serial.print ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
Serial << "The decimal equivalents are: " << li1 << " " << li2 << " " << li3 << " " << li4;
//return 0;
}
void loop() {
// put your main code here, to run repeatedly:
}
/*
Modified for Arduino from: http://www.cplusplus.com/reference/cstdlib/strtol/
Convert string to long integer: Maple Mini version by m. ray burnette: PUBLIC DOMAIN
Sketch uses 13,924 bytes (12%) of program storage space. Maximum is 108,000 bytes.
Global variables use 2,664 bytes of dynamic memory.
Following C++ libs not needed after Arduino 1.0.2
#include <stdio.h>
#include <stdlib.h>
*/
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
char * pEnd;
long int li1, li2, li3, li4;
void setup() {
// initialize the digital pin as an output.
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(9600);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
li1 = strtol (szNumbers,&pEnd,10); // BASE 10
li2 = strtol (pEnd,&pEnd,16); // HEX
li3 = strtol (pEnd,&pEnd,2); // Binary
li4 = strtol (pEnd,NULL,0); // Integer constant with prefixed base Octal or Hex
// Serial.print ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
Serial << "The decimal equivalents are: " << li1 << " " << li2 << " " << li3 << " " << li4;
//return 0;
}
void loop() {
// put your main code here, to run repeatedly:
}

View File

@ -1,52 +1,52 @@
/*
Knock Sensor
This sketch reads a piezo element to detect a knocking sound. It
reads an analog pin and compares the result to a set threshold. If
the result is greater than the threshold, it writes "knock" to the
serial port, and toggles the LED on pin 13.
The circuit:
* + connection of the piezo attached to analog in 0
* - connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground
http://www.arduino.cc/en/Tutorial/Knock
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Jun 2009
by Tom Igoe
Ported to the Maple
by LeafLabs
*/
// these constants won't change:
const int knockSensor = 0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Declare the knockSensor as an analog input:
pinMode(knockSensor, INPUT_ANALOG);
// declare the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the built-in LED
toggleLED();
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Knock!");
}
delay(100); // delay to avoid printing too often
}
/*
Knock Sensor
This sketch reads a piezo element to detect a knocking sound. It
reads an analog pin and compares the result to a set threshold. If
the result is greater than the threshold, it writes "knock" to the
serial port, and toggles the LED on pin 13.
The circuit:
* + connection of the piezo attached to analog in 0
* - connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground
http://www.arduino.cc/en/Tutorial/Knock
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Jun 2009
by Tom Igoe
Ported to the Maple
by LeafLabs
*/
// these constants won't change:
const int knockSensor = 0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Declare the knockSensor as an analog input:
pinMode(knockSensor, INPUT_ANALOG);
// declare the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the built-in LED
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));// Turn the LED from off to on, or on to off
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Knock!");
}
delay(100); // delay to avoid printing too often
}