Examples: mass code format. See example_formatter.conf

This commit is contained in:
Federico Fissore 2015-07-06 15:18:33 +02:00
parent c13cf02651
commit b5a130afb5
18 changed files with 179 additions and 188 deletions

View File

@ -10,8 +10,7 @@
#include <EEPROM.h> #include <EEPROM.h>
void setup() void setup() {
{
/*** /***
Iterate through each byte of the EEPROM storage. Iterate through each byte of the EEPROM storage.
@ -25,11 +24,14 @@ void setup()
This will make your code portable to all AVR processors. This will make your code portable to all AVR processors.
***/ ***/
for ( int i = 0 ; i < EEPROM.length() ; i++ ) for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0); EEPROM.write(i, 0);
}
// turn the LED on when we're done // turn the LED on when we're done
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
} }
void loop(){ /** Empty loop. **/ } void loop() {
/** Empty loop. **/
}

View File

@ -28,7 +28,9 @@ void setup(){
Serial.print("\n\nDone!"); Serial.print("\n\nDone!");
} }
void loop(){ /* Empty loop */ } void loop() {
/* Empty loop */
}
unsigned long eeprom_crc(void) { unsigned long eeprom_crc(void) {

View File

@ -63,4 +63,6 @@ void secondTest(){
Serial.println(customVar.name); Serial.println(customVar.name);
} }
void loop(){ /* Empty loop */ } void loop() {
/* Empty loop */
}

View File

@ -53,4 +53,6 @@ void setup(){
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
} }
void loop(){ /* Empty loop */ } void loop() {
/* Empty loop */
}

View File

@ -12,8 +12,7 @@
int address = 0; int address = 0;
byte value; byte value;
void setup() void setup() {
{
// initialize serial and wait for port to open: // initialize serial and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
@ -21,8 +20,7 @@ void setup()
} }
} }
void loop() void loop() {
{
// read a byte from the current address of the EEPROM // read a byte from the current address of the EEPROM
value = EEPROM.read(address); value = EEPROM.read(address);
@ -43,8 +41,9 @@ void loop()
This will make your code portable to all AVR processors. This will make your code portable to all AVR processors.
***/ ***/
address = address + 1; address = address + 1;
if(address == EEPROM.length()) if (address == EEPROM.length()) {
address = 0; address = 0;
}
/*** /***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an

View File

@ -16,10 +16,11 @@
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int address = 0; int address = 0;
void setup(){ /** EMpty setup **/ } void setup() {
/** EMpty setup **/
}
void loop() void loop() {
{
/*** /***
need to divide by 4 because analog inputs range from need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a 0 to 1023 and each byte of the EEPROM can only hold a
@ -55,8 +56,9 @@ void loop()
This will make your code portable to all AVR processors. This will make your code portable to all AVR processors.
***/ ***/
address = address + 1; address = address + 1;
if(address == EEPROM.length()) if (address == EEPROM.length()) {
address = 0; address = 0;
}
/*** /***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an

View File

@ -11,10 +11,11 @@
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0; int addr = 0;
void setup(){ /** Empty setup. **/} void setup() {
/** Empty setup. **/
}
void loop() void loop() {
{
/*** /***
Need to divide by 4 because analog inputs range from Need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a 0 to 1023 and each byte of the EEPROM can only hold a
@ -43,8 +44,9 @@ void loop()
This will make your code portable to all AVR processors. This will make your code portable to all AVR processors.
***/ ***/
addr = addr + 1; addr = addr + 1;
if(addr == EEPROM.length()) if (addr == EEPROM.length()) {
addr = 0; addr = 0;
}
/*** /***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an

View File

@ -29,8 +29,7 @@
SoftwareSerial mySerial(10, 11); // RX, TX SoftwareSerial mySerial(10, 11); // RX, TX
void setup() void setup() {
{
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
Serial.begin(57600); Serial.begin(57600);
while (!Serial) { while (!Serial) {
@ -45,11 +44,12 @@ void setup()
mySerial.println("Hello, world?"); mySerial.println("Hello, world?");
} }
void loop() // run over and over void loop() { // run over and over
{ if (mySerial.available()) {
if (mySerial.available())
Serial.write(mySerial.read()); Serial.write(mySerial.read());
if (Serial.available()) }
if (Serial.available()) {
mySerial.write(Serial.read()); mySerial.write(Serial.read());
} }
}

View File

@ -42,8 +42,7 @@ SoftwareSerial portOne(10, 11);
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
SoftwareSerial portTwo(8, 9); SoftwareSerial portTwo(8, 9);
void setup() void setup() {
{
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
@ -56,8 +55,7 @@ void setup()
portTwo.begin(9600); portTwo.begin(9600);
} }
void loop() void loop() {
{
// By default, the last intialized port is listening. // By default, the last intialized port is listening.
// when you want to listen on a port, explicitly select it: // when you want to listen on a port, explicitly select it:
portOne.listen(); portOne.listen();

View File

@ -12,16 +12,14 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(); // join i2c bus (address optional for master) Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps Serial.begin(9600); // start serial communication at 9600bps
} }
int reading = 0; int reading = 0;
void loop() void loop() {
{
// step 1: instruct sensor to read echoes // step 1: instruct sensor to read echoes
Wire.beginTransmission(112); // transmit to device #112 (0x70) Wire.beginTransmission(112); // transmit to device #112 (0x70)
// the address specified in the datasheet is 224 (0xE0) // the address specified in the datasheet is 224 (0xE0)
@ -44,8 +42,7 @@ void loop()
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor // step 5: receive reading from sensor
if (2 <= Wire.available()) // if two bytes were received if (2 <= Wire.available()) { // if two bytes were received
{
reading = Wire.read(); // receive high byte (overwrites previous reading) reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits

View File

@ -14,15 +14,13 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(); // join i2c bus (address optional for master) Wire.begin(); // join i2c bus (address optional for master)
} }
byte val = 0; byte val = 0;
void loop() void loop() {
{
Wire.beginTransmission(44); // transmit to device #44 (0x2c) Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet // device address is specified in datasheet
Wire.write(byte(0x00)); // sends instruction byte Wire.write(byte(0x00)); // sends instruction byte
@ -30,8 +28,7 @@ void loop()
Wire.endTransmission(); // stop transmitting Wire.endTransmission(); // stop transmitting
val++; // increment value val++; // increment value
if (val == 64) // if reached 64th position (max) if (val == 64) { // if reached 64th position (max)
{
val = 0; // start over from lowest value val = 0; // start over from lowest value
} }
delay(500); delay(500);

View File

@ -12,18 +12,15 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(); // join i2c bus (address optional for master) Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output Serial.begin(9600); // start serial for output
} }
void loop() void loop() {
{
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) // slave may send less than requested while (Wire.available()) { // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character Serial.print(c); // print the character
} }

View File

@ -12,15 +12,13 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(); // join i2c bus (address optional for master) Wire.begin(); // join i2c bus (address optional for master)
} }
byte x = 0; byte x = 0;
void loop() void loop() {
{
Wire.beginTransmission(8); // transmit to device #8 Wire.beginTransmission(8); // transmit to device #8
Wire.write("x is "); // sends five bytes Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte Wire.write(x); // sends one byte

View File

@ -12,24 +12,20 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(8); // join i2c bus with address #8 Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output Serial.begin(9600); // start serial for output
} }
void loop() void loop() {
{
delay(100); delay(100);
} }
// function that executes whenever data is received from master // function that executes whenever data is received from master
// this function is registered as an event, see setup() // this function is registered as an event, see setup()
void receiveEvent(int howMany) void receiveEvent(int howMany) {
{ while (1 < Wire.available()) { // loop through all but the last
while (1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character Serial.print(c); // print the character
} }

View File

@ -12,21 +12,18 @@
#include <Wire.h> #include <Wire.h>
void setup() void setup() {
{
Wire.begin(8); // join i2c bus with address #8 Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event Wire.onRequest(requestEvent); // register event
} }
void loop() void loop() {
{
delay(100); delay(100);
} }
// function that executes whenever data is requested by master // function that executes whenever data is requested by master
// this function is registered as an event, see setup() // this function is registered as an event, see setup()
void requestEvent() void requestEvent() {
{
Wire.write("hello "); // respond with message of 6 bytes Wire.write("hello "); // respond with message of 6 bytes
// as expected by master // as expected by master
} }