2,17 → 2,16 |
#include <Stepper.h> |
#include <Wire.h> |
|
#define light0 0x44 // A0 = L (I2C light0) |
#define light1 0x45 // A0 = H (I2C light0) |
#define address 0x44 // A0 = L (I2C address) |
|
const int steps = 200; //3200; // change this to fit the number of steps |
const int sspeed = 100; // stepper motor speed |
|
|
// initialize the stepper library on pins |
Stepper myStepper(steps, 9,10,11,12); |
|
// DS18S20 Temperature chip |
OneWire ds(5); // 1-Wire |
OneWire ds(1); // 1-Wire |
byte addr[8]; // Addres |
|
void setup() |
22,8 → 21,11 |
|
// initialize the serial port: |
Serial.begin(9600); |
|
// set the speed |
myStepper.setSpeed(8); |
|
Wire.begin(); // join i2c bus (light0 optional for master) |
Wire.begin(); // join i2c bus (address optional for master) |
|
// search for DS |
if ( !ds.search(addr)) |
67,12 → 69,7 |
digitalWrite(13, LOW); // blik |
// step one revolution in one direction: |
Serial.println("clockwise"); |
myStepper.setSpeed(sspeed/2); |
myStepper.step(30); |
myStepper.setSpeed(sspeed); |
myStepper.step(steps-50); |
myStepper.setSpeed(sspeed/2); |
myStepper.step(20); |
myStepper.step(steps); |
delay(50); |
digitalWrite(9, LOW); |
digitalWrite(10, LOW); |
86,12 → 83,7 |
digitalWrite(13, HIGH); // blik |
// step one revolution in the other direction: |
Serial.println("counterclockwise"); |
myStepper.setSpeed(sspeed/2); |
myStepper.step(-30); |
myStepper.setSpeed(sspeed); |
myStepper.step(-(steps-50)); |
myStepper.setSpeed(sspeed/2); |
myStepper.step(-20); |
myStepper.step(-steps); |
delay(50); |
digitalWrite(9, LOW); |
digitalWrite(10, LOW); |
105,13 → 97,7 |
ds.reset(); |
ds.select(addr); |
ds.write(0x44,1); // start conversion |
|
// Delay for measurement, maybe 750ms is enough, maybe not |
digitalWrite(13, HIGH); // set the LED on |
delay(500); |
digitalWrite(13, LOW); // set the LED off |
delay(500); |
|
delay(1000); // maybe 750ms is enough, maybe not |
present = ds.reset(); |
ds.select(addr); |
ds.write(0xBE); // Read Scratchpad |
130,107 → 116,57 |
Serial.println(); |
|
Serial.print("Light0: COMMAND="); |
|
// Setup device |
Wire.beginTransmission(light0); |
Wire.send(0x00); // sends light0 |
Wire.beginTransmission(address); |
Wire.send(0x00); // sends address |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
Wire.endTransmission(); // stop transmitting |
|
// Delay for measurement |
digitalWrite(13, HIGH); // set the LED on |
delay(55); |
delay(500); |
digitalWrite(13, LOW); // set the LED off |
delay(55); |
delay(500); |
|
// Connect to device and set register light0 |
Wire.beginTransmission(light0); |
Wire.send(0x00); // sends light0 |
|
// Connect to device and set register address |
Wire.beginTransmission(address); |
Wire.send(0x00); // sends address |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light0); |
Wire.requestFrom(light0, 1); |
Wire.beginTransmission(address); |
Wire.requestFrom(address, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.print(dd, HEX); |
|
Serial.print(" LSB="); |
// Connect to device and set register light0 |
Wire.beginTransmission(light0); |
Wire.send(0x01); // sends light0 |
// Connect to device and set register address |
Wire.beginTransmission(address); |
Wire.send(0x01); // sends address |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light0); |
Wire.requestFrom(light0, 1); |
Wire.beginTransmission(address); |
Wire.requestFrom(address, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.print(dd, HEX); |
|
Serial.print(" MSB="); |
// Connect to device and set register light0 |
Wire.beginTransmission(light0); |
Wire.send(0x02); // sends light0 |
// Connect to device and set register address |
Wire.beginTransmission(address); |
Wire.send(0x02); // sends address |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light0); |
Wire.requestFrom(light0, 1); |
Wire.beginTransmission(address); |
Wire.requestFrom(address, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.println(dd, HEX); |
|
Serial.print("Light1: COMMAND="); |
// Setup device |
Wire.beginTransmission(light1); |
Wire.send(0x00); // sends light0 |
Wire.send(0b11000001); // setup (eye light sensing; measurement range 2 [4000 lx]) |
Wire.endTransmission(); // stop transmitting |
|
// Delay for measurement |
digitalWrite(13, HIGH); // set the LED on |
delay(55); |
digitalWrite(13, LOW); // set the LED off |
delay(55); |
|
// Connect to device and set register light0 |
Wire.beginTransmission(light1); |
Wire.send(0x00); // sends light0 |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light1); |
Wire.requestFrom(light1, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.print(dd, HEX); |
|
Serial.print(" LSB="); |
// Connect to device and set register light0 |
Wire.beginTransmission(light1); |
Wire.send(0x01); // sends light0 |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light1); |
Wire.requestFrom(light1, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.print(dd, HEX); |
Serial.print("\n"); |
|
Serial.print(" MSB="); |
// Connect to device and set register light0 |
Wire.beginTransmission(light1); |
Wire.send(0x02); // sends light0 |
Wire.endTransmission(); // stop transmitting |
// Connect to device and request one byte |
Wire.beginTransmission(light1); |
Wire.requestFrom(light1, 1); |
dd = Wire.receive(); |
Wire.endTransmission(); // stop transmitting |
Serial.println(dd, HEX); |
|
Serial.print("X="); |
Serial.print(analogRead(A0), HEX); |
Serial.print(" Y="); |
Serial.print(analogRead(A1), HEX); |
Serial.print(" Z="); |
Serial.println(analogRead(A2), HEX); |
} |
|
|