-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ac5fae
commit 59f9cdc
Showing
33 changed files
with
458 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
int ledPin = 13; // the Arduino on-board LED | ||
|
||
void setup() { | ||
Serial.begin(9600, SERIAL_8N1); // set up 8-bit with no parity and 1 stop bit | ||
pinMode(ledPin, OUTPUT); // the ledPin is an output | ||
Serial.write("Hello from the Arduino"); | ||
} | ||
|
||
// this function loops as quickly as possible, forever | ||
void loop() { | ||
digitalWrite(ledPin, HIGH); // set the LED pin high | ||
delay(500); // high and low every second (flash at 1Hz) | ||
digitalWrite(ledPin, LOW); // set the LED pin low | ||
delay(500); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <Wire.h> // Uses the Two-Wire Interface (TWI) | ||
|
||
const byte slaveAddr = 0x44; // the slave address of the Arduino | ||
int registerAddr; // the shared register addr variable | ||
|
||
void setup() { // the setup function -- called once | ||
TWBR=100000L; // the i2c clk freq: 400000L = 400kHz | ||
Wire.begin(slaveAddr); // set Arduino as an I2C slave device | ||
Wire.onReceive(receiveRegister); // register receive listener below | ||
Wire.onRequest(respondData); // register respond listener below | ||
} | ||
|
||
void loop() { | ||
delay(1000); // loop each second -- reduce load | ||
} | ||
|
||
void receiveRegister(int x){ // handler called when data available | ||
registerAddr = Wire.read(); // read in one-byte address from PB | ||
} | ||
|
||
void respondData(){ // handler that is called on response | ||
Wire.write(registerAddr); // i.e., send the data back to the PB | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <Wire.h> // uses the Two-Wire Interface (TWI) | ||
const byte slaveAddr = 0x44; // the slave address of the Arduino | ||
int registerAddr; // the shared register addr variable | ||
const int analogInPin = A0; // analog input for the TMP36 | ||
int data[4]; // the data registers 00 to 0x03 | ||
|
||
void setup(){ | ||
TWBR=100000L; // set the i2c clk freq e.g. 100000L | ||
Wire.begin(slaveAddr); // set up the Arduino as an I2C slave | ||
Wire.onReceive(receiveRegister); // register receive listener below | ||
Wire.onRequest(respondData); // register respond listener below | ||
} | ||
|
||
void loop(){ // update registers every five seconds | ||
int adcValue = analogRead(analogInPin); // using a 10-bit ADC | ||
float curVoltage = adcValue * (5.0f/1024.0f); // Vcc = 5.0V, 10-bit | ||
float tempC = 25.0 + ((curVoltage-0.75f)/0.01f); // from datasheet | ||
float tempF = 32.0 + ((tempC * 9)/5); // deg. C to F | ||
data[0] = (int) tempC; // whole deg C (0x00) | ||
data[1] = (int) ((tempC - data[0])*100); // fract C (0x01) | ||
data[2] = (int) tempF; // whole deg F (0x02) | ||
data[3] = (int) ((tempF - data[2])*100); // fract F (0x03) | ||
delay(5000); // delay 5 seconds | ||
} | ||
|
||
void receiveRegister(int x){ // passes the number of bytes | ||
registerAddr = Wire.read(); // read in the one-byte address | ||
} | ||
|
||
void respondData(){ // respond function | ||
byte dataValue = 0x00; // default response value is 0x00 | ||
if ((registerAddr >= 0x00) && (registerAddr <0x04)){ | ||
dataValue = data[registerAddr]; | ||
} | ||
Wire.write(dataValue); // send the data back to the PB | ||
} |
Oops, something went wrong.