added some stuff
This commit is contained in:
parent
3a53fb0805
commit
32284da1c3
2 changed files with 118 additions and 0 deletions
43
DS1621/DS1621.ino
Normal file
43
DS1621/DS1621.ino
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <Wire.h>
|
||||
|
||||
#define DEV_ID 0x90 >> 1 // shift required by wire.h
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(DEV_ID); // connect to DS1621 (#0)
|
||||
Wire.write(0xAC); // Access Config
|
||||
Wire.write(0x02); // set for continuous conversion
|
||||
Wire.beginTransmission(DEV_ID); // restart
|
||||
Wire.write(0xEE); // start conversions
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int8_t firstByte;
|
||||
int8_t secondByte;
|
||||
float temp = 0;
|
||||
|
||||
delay(1000); // give time for measurement
|
||||
|
||||
Wire.beginTransmission(DEV_ID);
|
||||
Wire.write(0xAA); // read temperature command
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(DEV_ID, 2); // request two bytes from DS1621 (0.5 deg. resolution)
|
||||
|
||||
firstByte = Wire.read(); // get first byte
|
||||
secondByte = Wire.read(); // get second byte
|
||||
|
||||
temp = firstByte;
|
||||
|
||||
if (secondByte) // if there is a 0.5 deg difference
|
||||
temp += 0.5;
|
||||
|
||||
Serial.println(temp);
|
||||
|
||||
}
|
||||
75
PF575_I2C_8LED_BLINK/PF575_I2C_8LED_BLINK.ino
Normal file
75
PF575_I2C_8LED_BLINK/PF575_I2C_8LED_BLINK.ino
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <Wire.h>
|
||||
|
||||
/**
|
||||
* Arduino PF575/PCF8575 I2C I/O port exapander LED blink example
|
||||
*
|
||||
* Setup:
|
||||
*
|
||||
* 1. Connect A0, A1 and A2 to GND to set the address to 0x20.
|
||||
* 2. Connect SDL and SCL to the Arduino's I2C bus.
|
||||
* 3. Connect a LED to the P0 port of the I2C exapander.
|
||||
* In my setup I am using a PNP Transistor connected to 5V unsing
|
||||
* an resistor, the LED and the Arduino to make sure the LED gets
|
||||
* a current from Vcc and not from the I2C exapander port.
|
||||
*
|
||||
* This code is trying to explain how it works as simple as possible.
|
||||
* More detailed examples are found on the web. Search for pcf8575 and
|
||||
* you will find what you want.
|
||||
*/
|
||||
|
||||
// Set I2C address
|
||||
int address = 0x20;
|
||||
|
||||
void setup(){
|
||||
Wire.begin();
|
||||
pf575_write(word(B11111111,B11111111));
|
||||
delay(200);
|
||||
pf575_write(word(B00000000,B11111111));
|
||||
delay(200);
|
||||
pf575_write(word(B11111111,B11111111));
|
||||
delay(200);
|
||||
pf575_write(word(B00000000,B11111111));
|
||||
delay(200);
|
||||
pf575_write(word(B11111111,B11111111));
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
int dTime = 150;
|
||||
pf575_write(word(B11111110,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11111101,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11111011,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11110111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11101111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11011111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B10111111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B01111111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B10111111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11011111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11101111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11110111,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11111011,B11111111));
|
||||
delay(dTime);
|
||||
pf575_write(word(B11111101,B11111111));
|
||||
delay(dTime);
|
||||
}
|
||||
|
||||
// Function for writing two Bytes to the I2C expander device
|
||||
void pf575_write(uint16_t data) {
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(highByte(data));
|
||||
Wire.write(lowByte(data));
|
||||
Wire.endTransmission();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue