Moved examples to new dummy library item

This commit is contained in:
Roger Clark 2016-05-13 14:39:10 +10:00
parent 4ce00387d8
commit cc639cd9cb
58 changed files with 1651 additions and 1651 deletions

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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
}
}
/*
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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
}
}

View File

@ -33,4 +33,4 @@ void loop() {
// If so, turn the LED from on to off, or from off to on:
digitalWrite(33,!digitalRead(33));// Turn the LED from off to on, or on to off
}
}
}

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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
delay(100);
digitalWrite(33,!digitalRead(33));// 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);
}
}
/*
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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
delay(100);
digitalWrite(33,!digitalRead(33));// 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(33, OUTPUT);
}
void loop() {
digitalWrite(33,!digitalRead(33));// 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(33, OUTPUT);
}
void loop() {
digitalWrite(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Blink LED & count Demo");
}
void loop() {
digitalWrite(33, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(33, 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(33, 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
delay(100); // fast blink
}
Serial.println("Blink LED & count Demo");
}
void loop() {
digitalWrite(33, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(33, 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(33, 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(33,!digitalRead(33));// 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);
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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();
}
/*
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(33, 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(33,!digitalRead(33));// 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 33
#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(33,!digitalRead(33));// 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(33,!digitalRead(33));// Turn the LED from off to on, or on to off
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 33
#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(33,!digitalRead(33));// 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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);
}
}
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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");
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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");
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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("_");
}
}
}
/* 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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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];
}
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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);
}
/*
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(33, 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(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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);
}
// 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(33, 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(33,!digitalRead(33));// 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(33, OUTPUT);
Serial.begin(); // USB does not require BAUD
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(33,!digitalRead(33));// 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++;
}
/*
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(33, OUTPUT);
Serial.begin(); // USB does not require BAUD
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(33,!digitalRead(33));// 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(33, OUTPUT);
Serial.begin(9600);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(33,!digitalRead(33));// 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:
}
/*
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(33, OUTPUT);
Serial.begin(9600);
// wait for serial monitor to be connected.
while (!(Serial.isConnected() && (Serial.getDTR() || Serial.getRTS())))
{
digitalWrite(33,!digitalRead(33));// 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(33, 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(33,!digitalRead(33));// 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
}
/*
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(33, 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(33,!digitalRead(33));// 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
}