Skip to content

Commit f4573fd

Browse files
committed
Update all examples: Add Wire.begin, 115200bps default, link to library.
1 parent 677611f commit f4573fd

File tree

11 files changed

+311
-257
lines changed

11 files changed

+311
-257
lines changed

examples/analogWrite/analogWrite.ino

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,87 @@
11
/*************************************************************
2-
analogWrite.ino
3-
SparkFun SX1509 I/O Expander Example: pwm output (analogWrite)
4-
Jim Lindblom @ SparkFun Electronics
5-
Original Creation Date: September 21, 2015
6-
https://github.com/sparkfun/SparkFun_SX1509_Arduino_Library
2+
analogWrite.ino
3+
SparkFun SX1509 I/O Expander Example: pwm output (analogWrite)
4+
Jim Lindblom @ SparkFun Electronics
5+
Original Creation Date: September 21, 2015
6+
https://github.com/sparkfun/SparkFun_SX1509_Arduino_Library
77
8-
This example demonstrates the SX1509's analogWrite function.
9-
Connect an LED to the SX1509's pin 15 (or any other pin, they
10-
can all PWM!). The SX1509 can either sink or source current,
11-
just don't forget your limiting resistor!
8+
This example demonstrates the SX1509's analogWrite function.
9+
Connect an LED to the SX1509's pin 15 (or any other pin, they
10+
can all PWM!). The SX1509 can either sink or source current,
11+
just don't forget your limiting resistor!
1212
13-
Hardware Hookup:
14-
SX1509 Breakout ------ Arduino -------- Breadboard
15-
GND -------------- GND
16-
3V3 -------------- 3.3V
17-
SDA ------------ SDA (A4)
18-
SCL ------------ SCL (A5)
19-
15 -------------------------------- LED+
20-
LED- -/\/\/\- GND
13+
Hardware Hookup:
14+
SX1509 Breakout ------ Arduino -------- Breadboard
15+
GND -------------- GND
16+
3V3 -------------- 3.3V
17+
SDA ------------ SDA (A4)
18+
SCL ------------ SCL (A5)
19+
15 -------------------------------- LED+
20+
LED- -/\/\/\- GND
2121
330
2222
23-
Development environment specifics:
24-
IDE: Arduino 1.6.5
25-
Hardware Platform: Arduino Uno
26-
SX1509 Breakout Version: v2.0
23+
Development environment specifics:
24+
IDE: Arduino 1.6.5
25+
Hardware Platform: Arduino Uno
26+
SX1509 Breakout Version: v2.0
2727
28-
This code is beerware; if you see me (or any other SparkFun
29-
employee) at the local, and you've found our code helpful,
30-
please buy us a round!
28+
This code is beerware; if you see me (or any other SparkFun
29+
employee) at the local, and you've found our code helpful,
30+
please buy us a round!
3131
32-
Distributed as-is; no warranty is given.
32+
Distributed as-is; no warranty is given.
3333
*************************************************************/
3434

35-
#include <Wire.h> // Include the I2C library (required)
36-
#include <SparkFunSX1509.h> // Include SX1509 library
35+
#include <Wire.h> // Include the I2C library (required)
36+
#include <SparkFunSX1509.h> //Click here for the library: http://librarymanager/All#SparkFun_SX1509
3737

3838
// SX1509 I2C address (set by ADDR1 and ADDR0 (00 by default):
39-
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
40-
SX1509 io; // Create an SX1509 object to be used throughout
39+
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
40+
SX1509 io; // Create an SX1509 object to be used throughout
4141

4242
// SX1509 Pin definition:
4343
const byte SX1509_LED_PIN = 15; // LED to SX1509's pin 15
4444

45-
void setup()
45+
void setup()
4646
{
47-
// Call io.begin(<address>) to initialize the SX1509. If it
47+
Serial.begin(115200);
48+
Serial.println("SX1509 Example");
49+
50+
Wire.begin();
51+
52+
// Call io.begin(<address>) to initialize the SX1509. If it
4853
// successfully communicates, it'll return 1.
49-
if (!io.begin(SX1509_ADDRESS))
54+
if (io.begin(SX1509_ADDRESS) == false)
5055
{
51-
while (1) ; // If we fail to communicate, loop forever.
56+
Serial.println("Failed to communicate. Check wiring and address of SX1509.");
57+
while (1)
58+
; // If we fail to communicate, loop forever.
5259
}
53-
54-
// Use the pinMode(<pin>, <mode>) function to set our led
60+
61+
// Use the pinMode(<pin>, <mode>) function to set our led
5562
// pin as an ANALOG_OUTPUT, which is required for PWM output
5663
io.pinMode(SX1509_LED_PIN, ANALOG_OUTPUT);
5764
}
5865

5966
void loop()
6067
{
61-
// Ramp brightness up, from 0-255, delay 2ms in between
68+
// Ramp brightness up, from 0-255, delay 2ms in between
6269
// analogWrite's
63-
for (int brightness=0; brightness<256; brightness++)
70+
for (int brightness = 0; brightness < 256; brightness++)
6471
{
65-
// Call io.analogWrite(<pin>, <0-255>) to configure the
72+
// Call io.analogWrite(<pin>, <0-255>) to configure the
6673
// PWM duty cycle
6774
io.analogWrite(SX1509_LED_PIN, brightness);
6875
delay(2); // Delay 2 milliseconds
6976
}
7077
delay(500); // Delay half-a-second
71-
72-
// Ramp brightness down, from 255-0, delay 2ms in between
78+
79+
// Ramp brightness down, from 255-0, delay 2ms in between
7380
// analogWrite's
74-
for (int brightness=255; brightness>=0; brightness--)
81+
for (int brightness = 255; brightness >= 0; brightness--)
7582
{
7683
io.analogWrite(SX1509_LED_PIN, brightness);
7784
delay(2); // Delay 2 milliseconds
7885
}
7986
delay(500); // Delay half-a-second
80-
8187
}

examples/blink/blink.ino

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,30 @@ please buy us a round!
3232
Distributed as-is; no warranty is given.
3333
*************************************************************/
3434

35-
#include <Wire.h> // Include the I2C library (required)
36-
#include <SparkFunSX1509.h> // Include SX1509 library
35+
#include <Wire.h> // Include the I2C library (required)
36+
#include <SparkFunSX1509.h> //Click here for the library: http://librarymanager/All#SparkFun_SX1509
3737

3838
// SX1509 I2C address (set by ADDR1 and ADDR0 (00 by default):
39-
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
40-
SX1509 io; // Create an SX1509 object to be used throughout
39+
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
40+
SX1509 io; // Create an SX1509 object to be used throughout
4141

4242
// SX1509 Pin definition:
4343
const byte SX1509_LED_PIN = 15; // LED to SX1509's pin 15
4444

45-
void setup()
45+
void setup()
4646
{
47-
// Call io.begin(<address>) to initialize the SX1509. If it
47+
Serial.begin(115200);
48+
Serial.println("SX1509 Example");
49+
50+
Wire.begin();
51+
52+
// Call io.begin(<address>) to initialize the SX1509. If it
4853
// successfully communicates, it'll return 1.
49-
if (!io.begin(SX1509_ADDRESS))
54+
if (io.begin(SX1509_ADDRESS) == false)
5055
{
51-
while (1) ; // If we fail to communicate, loop forever.
56+
Serial.println("Failed to communicate. Check wiring and address of SX1509.");
57+
while (1)
58+
; // If we fail to communicate, loop forever.
5259
}
5360

5461
// Set up the SX1509's clock to use the internal 2MHz
@@ -57,9 +64,9 @@ void setup()
5764
// clock by 2 ^ (4-1) (8, ie. 250kHz). The divider parameter
5865
// can be anywhere between 1-7.
5966
io.clock(INTERNAL_CLOCK_2MHZ, 4);
60-
67+
6168
io.pinMode(SX1509_LED_PIN, OUTPUT); // Set LED pin to OUTPUT
62-
69+
6370
// Blink the LED pin -- ~1000 ms LOW, ~500 ms HIGH:
6471
io.blink(SX1509_LED_PIN, 1000, 500);
6572
// The timing parameters are in milliseconds, but they

examples/breathe/breathe.ino

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,47 @@ please buy us a round!
3333
Distributed as-is; no warranty is given.
3434
*************************************************************/
3535

36-
#include <Wire.h> // Include the I2C library (required)
37-
#include <SparkFunSX1509.h> // Include SX1509 library
36+
#include <Wire.h> // Include the I2C library (required)
37+
#include <SparkFunSX1509.h> //Click here for the library: http://librarymanager/All#SparkFun_SX1509
3838

3939
// SX1509 I2C address (set by ADDR1 and ADDR0 (00 by default):
40-
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
41-
SX1509 io; // Create an SX1509 object to be used throughout
40+
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
41+
SX1509 io; // Create an SX1509 object to be used throughout
4242

4343
// SX1509 Pin definition:
4444
const byte SX1509_LED_PIN = 15; // LED to SX1509's pin 15
4545

46-
void setup()
46+
void setup()
4747
{
48+
Serial.begin(115200);
49+
Serial.println("SX1509 Example");
50+
51+
Wire.begin();
52+
4853
// Call io.begin(<address>) to initialize the SX1509. If it
4954
// successfully communicates, it'll return 1.
50-
if (!io.begin(SX1509_ADDRESS))
55+
if (io.begin(SX1509_ADDRESS) == false)
5156
{
52-
while (1) ; // If we fail to communicate, loop forever.
57+
Serial.println("Failed to communicate. Check wiring and address of SX1509.");
58+
while (1)
59+
; // If we fail to communicate, loop forever.
5360
}
5461

5562
// Use the internal 2MHz oscillator.
5663
// Set LED clock to 500kHz (2MHz / (2^(3-1)):
5764
io.clock(INTERNAL_CLOCK_2MHZ, 3);
58-
65+
5966
// To breathe an LED, make sure you set it as an
6067
// ANALOG_OUTPUT, so we can PWM the pin:
6168
io.pinMode(SX1509_LED_PIN, ANALOG_OUTPUT);
62-
69+
6370
// Breathe an LED: 1000ms LOW, 500ms HIGH,
6471
// 500ms to rise from low to high
6572
// 250ms to fall from high to low
6673
io.breathe(SX1509_LED_PIN, 1000, 500, 500, 250);
67-
// The timing parameters are in milliseconds, but they
68-
// aren't 100% exact. The library will estimate to try to
69-
// get them as close as possible. Play with the clock
74+
// The timing parameters are in milliseconds, but they
75+
// aren't 100% exact. The library will estimate to try to
76+
// get them as close as possible. Play with the clock
7077
// divider to maybe get more accurate timing.
7178
}
7279

examples/clock/clock.ino

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,29 @@ please buy us a round!
3030
Distributed as-is; no warranty is given.
3131
*************************************************************/
3232

33-
#include <Wire.h> // Include the I2C library (required)
34-
#include <SparkFunSX1509.h> // Include SX1509 library
33+
#include <Wire.h> // Include the I2C library (required)
34+
#include <SparkFunSX1509.h> //Click here for the library: http://librarymanager/All#SparkFun_SX1509
3535

3636
// SX1509 I2C address (set by ADDR1 and ADDR0 (00 by default):
37-
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
38-
SX1509 io; // Create an SX1509 object to be used throughout
37+
const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
38+
SX1509 io; // Create an SX1509 object to be used throughout
3939

40-
void setup()
40+
void setup()
4141
{
42+
Serial.begin(115200);
43+
Serial.println("SX1509 Example");
44+
45+
Wire.begin();
46+
4247
// Call io.begin(<address>) to initialize the SX1509. If it
4348
// successfully communicates, it'll return 1.
44-
if (!io.begin(SX1509_ADDRESS))
49+
if (io.begin(SX1509_ADDRESS) == false)
4550
{
46-
while (1) ; // If we fail to communicate, loop forever.
51+
Serial.println("Failed to communicate. Check wiring and address of SX1509.");
52+
while (1)
53+
; // If we fail to communicate, loop forever.
4754
}
48-
55+
4956
// Configure clock:
5057
// - INTERNAL_CLOCK_2MHZ: Set clock to internal 2MHz
5158
// - 2: Set LED clock to divide by 2^(2-1) (2)
@@ -58,6 +65,6 @@ void setup()
5865
io.clock(INTERNAL_CLOCK_2MHZ, 2, OUTPUT, outputFreq);
5966
}
6067

61-
void loop()
68+
void loop()
6269
{
6370
}

0 commit comments

Comments
 (0)