Commit 9d1af722 authored by onny's avatar onny

first commit

parents
// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
int i2c_read_word(uint8_t dev, uint8_t addr)
{
int rdata = -1;
// First set up the address
Wire.beginTransmission(dev);
Wire.write(addr);
Wire.endTransmission();
// Now, read the data
Wire.requestFrom(dev, (uint8_t)1);
if (Wire.available()) {
rdata = Wire.read();
}
return rdata;
}
void loop()
{
i2c_read_word(0x0B, 0x09);
delay(500);
}
#include <Wire.h>
#define I2CDEVICE 0x0B
int REDLED =7;
int GREENLED =6;
int BLUELED = 5;
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(REDLED, OUTPUT);
pinMode(GREENLED, OUTPUT);
pinMode(BLUELED, OUTPUT);
digitalWrite(REDLED, HIGH);
digitalWrite(GREENLED, HIGH);
digitalWrite(BLUELED, HIGH);
}
void loop()
{
if (get_battery_state()) {
digitalWrite(GREENLED, LOW);
} else {
digitalWrite(GREENLED, HIGH);
}
delay(500);
}
unsigned int i2c_smbus_read_word ( uint8_t command ) {
unsigned int buffer = 0;
Wire.beginTransmission(I2CDEVICE);
Wire.write(command);
Wire.endTransmission();
Wire.requestFrom(I2CDEVICE,2);
buffer = Wire.read();
buffer += Wire.read() << 8;
return buffer;
}
unsigned int get_battery_state () {
if ((int)i2c_smbus_read_word(0x0a) > 0) {
return 1;
}
if ((int)i2c_smbus_read_word(0x0a) == 0) {
return 0;
}
if ((int)i2c_smbus_read_word(0x0a) < 0) {
return 2;
}
}
int REDLED =7;
int BLUELED =6;
int GREENLED = 5;
void setup()
{
pinMode(REDLED, OUTPUT);
pinMode(GREENLED, OUTPUT);
pinMode(BLUELED, OUTPUT);
}
void loop()
{
AllOff();
digitalWrite(REDLED, LOW);
delay(500);
AllOff();
digitalWrite(GREENLED, LOW);
delay(500);
AllOff();
digitalWrite(BLUELED, LOW);
delay(500);
}
void AllOff()
{
digitalWrite(REDLED, HIGH);
digitalWrite(GREENLED, HIGH);
digitalWrite(BLUELED, HIGH);
delay(500);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment