mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Auto Format all built-in examples
The only changes I left out are the Max/MSP patches because I don't know whether the indentation would break them.
This commit is contained in:
parent
8f48433f33
commit
eee3e5ba18
@ -2,20 +2,20 @@
|
||||
Blink
|
||||
Turns an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
||||
the correct LED pin independent of which board is used.
|
||||
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
||||
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 May 2014
|
||||
by Scott Fitzgerald
|
||||
|
||||
|
||||
modified 2 Sep 2016
|
||||
by Arturo Guadalupi
|
||||
|
||||
|
||||
modified 8 Sep 2016
|
||||
by Colby Newman
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@
|
||||
Reads a digital input on pin 2, prints the result to the Serial Monitor
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
// digital pin 2 has a pushbutton attached to it. Give it a name:
|
||||
int pushButton = 2;
|
||||
|
@ -7,11 +7,11 @@
|
||||
The analogWrite() function uses PWM, so if
|
||||
you want to change the pin you're using, be
|
||||
sure to use another PWM capable pin. On most
|
||||
Arduino, the PWM pins are identified with
|
||||
Arduino, the PWM pins are identified with
|
||||
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
int led = 9; // the PWM pin the LED is attached to
|
||||
int brightness = 0; // how bright the LED is
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
The circuit:
|
||||
- Use the onboard LED.
|
||||
- Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||
- Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
||||
the correct LED pin independent of which board is used.
|
||||
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
||||
@ -25,7 +25,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||
*/
|
||||
*/
|
||||
|
||||
// constants won't change. Used here to set a pin number:
|
||||
const int ledPin = LED_BUILTIN;// the number of the LED pin
|
||||
|
@ -22,7 +22,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Button
|
||||
*/
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
|
@ -28,7 +28,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
This example code is in the public domain
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
//start serial connection
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/ButtonStateChange
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// this constant won't change:
|
||||
const int buttonPin = 2; // the pin that the pushbutton is attached to
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Tone3
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "pitches.h"
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Tone
|
||||
|
||||
*/
|
||||
*/
|
||||
#include "pitches.h"
|
||||
|
||||
// notes in the melody:
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Tone4
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Tone2
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/AnalogInput
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
int sensorPin = A0; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
const int lowestPin = 2;
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// These constants won't change:
|
||||
const int sensorPin = A0; // pin that the sensor is attached to
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
int ledPin = 9; // LED connected to digital pin 9
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
<http://www.zambetti.com>
|
||||
|
||||
*/
|
||||
*/
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Dimmer
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
const int ledPin = 9; // the pin that the LED is attached to
|
||||
|
||||
@ -80,7 +80,7 @@ void loop() {
|
||||
// a single byte
|
||||
port.write(mouseX);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Max/MSP v5 patch for this example
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Graph
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// initialize the serial communication:
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Midi
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Set MIDI baud rate:
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
|
@ -21,7 +21,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/PhysicalPixel
|
||||
*/
|
||||
*/
|
||||
|
||||
const int ledPin = 13; // the pin that the LED is attached to
|
||||
int incomingByte; // a variable to read incoming serial data into
|
||||
@ -121,7 +121,7 @@ void loop() {
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
Max/MSP version 5 patch to run with this example:
|
||||
|
@ -13,12 +13,12 @@
|
||||
|
||||
created 13 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
modified 14 Mar 2016
|
||||
by Arturo Guadalupi
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
// pins for the LEDs:
|
||||
const int redPin = 3;
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SerialCallResponse
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
int firstSensor = 0; // first analog sensor
|
||||
int secondSensor = 0; // second analog sensor
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
int firstSensor = 0; // first analog sensor
|
||||
int secondSensor = 0; // second analog sensor
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
NOTE: The serialEvent() feature is not available on the
|
||||
Leonardo, Micro, or other ATmega32U4 based boards.
|
||||
|
||||
|
||||
Created 9 May 2011
|
||||
by Tom Igoe
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SerialEvent
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
String inputString = ""; // a String to hold incoming data
|
||||
boolean stringComplete = false; // whether the string is complete
|
||||
@ -45,7 +45,7 @@ void loop() {
|
||||
hardware serial RX. This routine is run between each
|
||||
time loop() runs, so using delay inside loop can delay
|
||||
response. Multiple bytes of data may be available.
|
||||
*/
|
||||
*/
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
// get the new byte:
|
||||
|
@ -14,7 +14,7 @@
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
const int redPin = A0; // sensor to control red color
|
||||
const int greenPin = A1; // sensor to control green color
|
||||
@ -86,7 +86,7 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Array
|
||||
*/
|
||||
*/
|
||||
|
||||
int timer = 100; // The higher the number, the slower the timing.
|
||||
int ledPins[] = {
|
||||
|
@ -15,7 +15,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/ForLoop
|
||||
*/
|
||||
*/
|
||||
|
||||
int timer = 100; // The higher the number, the slower the timing.
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/IfStatement
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// These constants won't change:
|
||||
const int analogPin = A0; // pin that the sensor is attached to
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/WhileLoop
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
// These constants won't change:
|
||||
|
@ -20,7 +20,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SwitchCase
|
||||
*/
|
||||
*/
|
||||
|
||||
// these constants won't change. They are the
|
||||
// lowest and highest readings you get from your sensor:
|
||||
|
@ -18,7 +18,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/SwitchCase2
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// initialize serial communication:
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
// these constants won't change:
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// these constants won't change:
|
||||
const int xPin = 2; // X output of the accelerometer
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// this constant won't change. It's the pin number
|
||||
// of the sensor's output:
|
||||
|
@ -31,7 +31,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/RowColumnScanning
|
||||
|
||||
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
// 2-dimensional array of row pin numbers:
|
||||
|
@ -18,7 +18,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BarGraph
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
// these constants won't change:
|
||||
|
@ -9,7 +9,7 @@
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -11,7 +11,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringAdditionOperator
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
// declare three Strings:
|
||||
String stringOne, stringTwo, stringThree;
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringAppendOperator
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
String stringOne, stringTwo;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringCaseChanges
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringCharacters
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringComparisonOperators
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
String stringOne, stringTwo;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringConstructors
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringIndexOf
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringLengthTrim
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
String txtMsg = ""; // a string for incoming text
|
||||
unsigned int lastStringLength = txtMsg.length(); // previous length of the String
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringLengthTrim
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringReplace
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringStartsWithEndsWith
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -10,7 +10,7 @@
|
||||
http://www.arduino.cc/en/Tutorial/StringSubstring
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
|
@ -11,7 +11,7 @@
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
*/
|
||||
|
||||
String inString = ""; // string to hold input
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
This example is in the public domain
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardLogout
|
||||
*/
|
||||
*/
|
||||
|
||||
#define OSX 0
|
||||
#define WINDOWS 1
|
||||
|
@ -18,7 +18,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardMessage
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
This example is in the public domain
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardSerial
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Keyboard.h"
|
||||
#include "Mouse.h"
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Mouse.h"
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "Mouse.h"
|
||||
|
||||
@ -98,7 +98,7 @@ void loop() {
|
||||
/*
|
||||
reads an axis (0 or 1 for x or y) and scales the
|
||||
analog input range to a range from 0 to <range>
|
||||
*/
|
||||
*/
|
||||
|
||||
int readAxis(int thisAxis) {
|
||||
// read the analog input:
|
||||
|
@ -16,7 +16,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// named constant for the pin the sensor is connected to
|
||||
const int sensorPin = A0;
|
||||
|
@ -20,7 +20,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
const int greenLEDPin = 9; // LED connected to digital pin 9
|
||||
const int redLEDPin = 10; // LED connected to digital pin 10
|
||||
@ -89,7 +89,7 @@ void loop() {
|
||||
Serial.println(blueValue);
|
||||
|
||||
/*
|
||||
Now that you have a usable value, it's time to PWM the LED.
|
||||
Now that you have a usable value, it's time to PWM the LED.
|
||||
*/
|
||||
analogWrite(redLEDPin, redValue);
|
||||
analogWrite(greenLEDPin, greenValue);
|
||||
|
@ -16,7 +16,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// include the Servo library
|
||||
#include <Servo.h>
|
||||
|
@ -17,7 +17,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// named constant for the switch pin
|
||||
const int switchPin = 8;
|
||||
|
@ -19,7 +19,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// named constants for the switch and motor pins
|
||||
const int switchPin = 2; // the number of the switch pin
|
||||
|
@ -20,7 +20,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
const int controlPin1 = 2; // connected to pin 7 on the H-bridge
|
||||
const int controlPin2 = 3; // connected to pin 2 on the H-bridge
|
||||
|
@ -19,7 +19,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
@ -24,7 +24,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// import the library
|
||||
#include <Servo.h>
|
||||
|
@ -21,7 +21,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
// import the library (must be located in the
|
||||
// Arduino/libraries directory)
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
Software required :
|
||||
Processing (3.0 or newer) http://processing.org
|
||||
Active Internet connection
|
||||
Active Internet connection
|
||||
|
||||
Created 18 September 2012
|
||||
by Scott Fitzgerald
|
||||
@ -18,7 +18,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
@ -99,4 +99,4 @@ void loop() {
|
||||
// draw the Arduino logo
|
||||
image(logo, 0, 0);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
@ -16,7 +16,7 @@
|
||||
http://www.arduino.cc/starterKit
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
const int optoPin = 2; // the pin the optocoupler is connected to
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
//
|
||||
// Alternatively you can use any other digital pin by configuring software ('BitBanged')
|
||||
// SPI and having appropriate defines for PIN_MOSI, PIN_MISO and PIN_SCK.
|
||||
//
|
||||
//
|
||||
// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...)
|
||||
// as the programmer, make sure to not expose any of the programmer's pins to 5V.
|
||||
// A simple way to accomplish this is to power the complete system (programmer
|
||||
@ -68,7 +68,7 @@
|
||||
// Configure which pins to use:
|
||||
|
||||
// The standard pin configuration.
|
||||
#ifndef ARDUINO_HOODLOADER2
|
||||
#ifndef ARDUINO_HOODLOADER2
|
||||
|
||||
#define RESET 10 // Use pin 10 to reset the target rather than SS
|
||||
#define LED_HB 9
|
||||
@ -88,10 +88,10 @@
|
||||
|
||||
#endif
|
||||
|
||||
// HOODLOADER2 means running sketches on the ATmega16U2
|
||||
// HOODLOADER2 means running sketches on the ATmega16U2
|
||||
// serial converter chips on Uno or Mega boards.
|
||||
// We must use pins that are broken out:
|
||||
#else
|
||||
#else
|
||||
|
||||
#define RESET 4
|
||||
#define LED_HB 7
|
||||
@ -166,51 +166,51 @@ void pulse(int pin, int times);
|
||||
#define SPI_MODE0 0x00
|
||||
|
||||
class SPISettings {
|
||||
public:
|
||||
// clock is in Hz
|
||||
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock){
|
||||
(void) bitOrder;
|
||||
(void) dataMode;
|
||||
};
|
||||
public:
|
||||
// clock is in Hz
|
||||
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clock(clock) {
|
||||
(void) bitOrder;
|
||||
(void) dataMode;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t clock;
|
||||
private:
|
||||
uint32_t clock;
|
||||
|
||||
friend class BitBangedSPI;
|
||||
friend class BitBangedSPI;
|
||||
};
|
||||
|
||||
class BitBangedSPI {
|
||||
public:
|
||||
void begin() {
|
||||
digitalWrite(PIN_SCK, LOW);
|
||||
digitalWrite(PIN_MOSI, LOW);
|
||||
pinMode(PIN_SCK, OUTPUT);
|
||||
pinMode(PIN_MOSI, OUTPUT);
|
||||
pinMode(PIN_MISO, INPUT);
|
||||
}
|
||||
|
||||
void beginTransaction(SPISettings settings) {
|
||||
pulseWidth = (500000 + settings.clock - 1) / settings.clock;
|
||||
if (pulseWidth == 0)
|
||||
pulseWidth = 1;
|
||||
}
|
||||
|
||||
void end() {}
|
||||
|
||||
uint8_t transfer (uint8_t b) {
|
||||
for (unsigned int i = 0; i < 8; ++i) {
|
||||
digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW);
|
||||
digitalWrite(PIN_SCK, HIGH);
|
||||
delayMicroseconds(pulseWidth);
|
||||
b = (b << 1) | digitalRead(PIN_MISO);
|
||||
digitalWrite(PIN_SCK, LOW); // slow pulse
|
||||
delayMicroseconds(pulseWidth);
|
||||
public:
|
||||
void begin() {
|
||||
digitalWrite(PIN_SCK, LOW);
|
||||
digitalWrite(PIN_MOSI, LOW);
|
||||
pinMode(PIN_SCK, OUTPUT);
|
||||
pinMode(PIN_MOSI, OUTPUT);
|
||||
pinMode(PIN_MISO, INPUT);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long pulseWidth; // in microseconds
|
||||
void beginTransaction(SPISettings settings) {
|
||||
pulseWidth = (500000 + settings.clock - 1) / settings.clock;
|
||||
if (pulseWidth == 0)
|
||||
pulseWidth = 1;
|
||||
}
|
||||
|
||||
void end() {}
|
||||
|
||||
uint8_t transfer (uint8_t b) {
|
||||
for (unsigned int i = 0; i < 8; ++i) {
|
||||
digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW);
|
||||
digitalWrite(PIN_SCK, HIGH);
|
||||
delayMicroseconds(pulseWidth);
|
||||
b = (b << 1) | digitalRead(PIN_MISO);
|
||||
digitalWrite(PIN_SCK, LOW); // slow pulse
|
||||
delayMicroseconds(pulseWidth);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long pulseWidth; // in microseconds
|
||||
};
|
||||
|
||||
static BitBangedSPI SPI;
|
||||
|
Loading…
x
Reference in New Issue
Block a user