diff options
author | Federico Fissore <f.fissore@arduino.cc> | 2015-07-06 15:18:33 +0200 |
---|---|---|
committer | Federico Fissore <f.fissore@arduino.cc> | 2015-07-06 15:19:05 +0200 |
commit | b5a130afb51c971fd7ceca8834b6055f1eada253 (patch) | |
tree | d1e964f67822e9b3f10382573a9579c85b9c3e3f /libraries/Wire | |
parent | c13cf02651e178ea7941a82bee364d82c6b19b9c (diff) |
Examples: mass code format. See example_formatter.conf
Diffstat (limited to 'libraries/Wire')
6 files changed, 18 insertions, 36 deletions
diff --git a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino index d97a9e3..4d0a68f 100644 --- a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino +++ b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -12,16 +12,14 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial communication at 9600bps } int reading = 0; -void loop() -{ +void loop() { // step 1: instruct sensor to read echoes Wire.beginTransmission(112); // transmit to device #112 (0x70) // 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 // 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 = reading << 8; // shift high byte to be high 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits diff --git a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino index 4d1580a..5fb91fb 100644 --- a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino +++ b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -14,15 +14,13 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) } byte val = 0; -void loop() -{ +void loop() { Wire.beginTransmission(44); // transmit to device #44 (0x2c) // device address is specified in datasheet Wire.write(byte(0x00)); // sends instruction byte @@ -30,8 +28,7 @@ void loop() Wire.endTransmission(); // stop transmitting 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 } delay(500); diff --git a/libraries/Wire/examples/master_reader/master_reader.ino b/libraries/Wire/examples/master_reader/master_reader.ino index 2d2419b..ecab72a 100644 --- a/libraries/Wire/examples/master_reader/master_reader.ino +++ b/libraries/Wire/examples/master_reader/master_reader.ino @@ -12,18 +12,15 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output } -void loop() -{ +void loop() { 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 Serial.print(c); // print the character } diff --git a/libraries/Wire/examples/master_writer/master_writer.ino b/libraries/Wire/examples/master_writer/master_writer.ino index 9933cc2..5cbea11 100644 --- a/libraries/Wire/examples/master_writer/master_writer.ino +++ b/libraries/Wire/examples/master_writer/master_writer.ino @@ -12,15 +12,13 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) } byte x = 0; -void loop() -{ +void loop() { Wire.beginTransmission(8); // transmit to device #8 Wire.write("x is "); // sends five bytes Wire.write(x); // sends one byte diff --git a/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/libraries/Wire/examples/slave_receiver/slave_receiver.ino index 53df274..8051d53 100644 --- a/libraries/Wire/examples/slave_receiver/slave_receiver.ino +++ b/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -12,24 +12,20 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(8); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); // start serial for output } -void loop() -{ +void loop() { delay(100); } // function that executes whenever data is received from master // this function is registered as an event, see setup() -void receiveEvent(int howMany) -{ - while (1 < Wire.available()) // loop through all but the last - { +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last char c = Wire.read(); // receive byte as a character Serial.print(c); // print the character } diff --git a/libraries/Wire/examples/slave_sender/slave_sender.ino b/libraries/Wire/examples/slave_sender/slave_sender.ino index 26b9e52..d2e72bb 100644 --- a/libraries/Wire/examples/slave_sender/slave_sender.ino +++ b/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -12,21 +12,18 @@ #include <Wire.h> -void setup() -{ +void setup() { Wire.begin(8); // join i2c bus with address #8 Wire.onRequest(requestEvent); // register event } -void loop() -{ +void loop() { delay(100); } // function that executes whenever data is requested by master // this function is registered as an event, see setup() -void requestEvent() -{ +void requestEvent() { Wire.write("hello "); // respond with message of 6 bytes // as expected by master } |