/*
ᅠDouble Analog input, Double analog output, serial output
ᅠReads from two analog input pins, a T000020 Accelerometer Module connected to I0 and I1, maps the result to a range from 0 to 255
ᅠand uses the result to set the pulsewidth modulation (PWM) on two T010111 LED Modules connected on O0 and O1.
ᅠAlso prints the results to the serial monitor.
ᅠcreated 29 Dec. 2008
ᅠModified 4 Sep 2010
ᅠby Tom Igoe
ᅠmodified 7 dec 2010
ᅠby Davide Gomba
ᅠThis example code is in the public domain.
ᅠ*/
#define O0 11
#define O1 10
#define O2 9
#define O3 6
#define O4 5
#define O5 3
#define I0 A0
#define I1 A1
#define I2 A2
#define I3 A3
#define I4 A4
#define I5 A5
// These constants won't change. ᅠThey're used to give names
// to the pins used:
const int analogInPin1 = I0; ᅠ// Analog input pin that the Accelerometer's first pin is attached to
const int analogInPin2 = I1; ᅠ// Analog input pin that the Accelerometer's second pin is attached to
const int analogOutPin1= O0; // Analog output pin that the LED is attached to
const int analogOutPin2= O1; // Analog output pin that the LED is attached to
int sensorValue1 = 0; ᅠ ᅠ ᅠ ᅠ// value read from the Accelerometer's first pin
int sensorValue2 = 0; ᅠ ᅠ ᅠ ᅠ// value read from the Accelerometer's second pin
int outputValue1 = 0; ᅠ ᅠ ᅠ ᅠ// value output to the PWM (analog out)
int outputValue2 = 0; ᅠ ᅠ ᅠ ᅠ// value output to the PWM (analog out)
void setup() {
ᅠ // initialize serial communications at 9600 bps:
ᅠ Serial.begin(9600);
}
void loop() {
ᅠ // read the both analog in values:
ᅠ sensorValue1 = analogRead(analogInPin1); ᅠ
ᅠ sensorValue2 = analogRead(analogInPin2); ᅠ
ᅠ // map it to the range of the analog out:
ᅠ outputValue1 = map(sensorValue1, 0, 1023, 0, 255); ᅠ
ᅠ outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
ᅠ // change the analog out value:
ᅠ analogWrite(analogOutPin1, outputValue1); ᅠ ᅠ
ᅠ analogWrite(analogOutPin2, outputValue2); ᅠ
ᅠ // print the results to the serial monitor:
ᅠ Serial.print("accelerometer X = " ); ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ
ᅠ Serial.print(sensorValue1); ᅠ
ᅠ Serial.print("\t accelerometer Y = " ); ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ
ᅠ Serial.print(sensorValue2); ᅠ ᅠ
ᅠ Serial.print("\t output 1 = "); ᅠ ᅠ ᅠ
ᅠ Serial.print(outputValue1); ᅠ
ᅠ Serial.print("\t output 2 = "); ᅠ ᅠ ᅠ
ᅠ Serial.println(outputValue2);
ᅠ // wait 10 milliseconds before the next loop
ᅠ // for the analog-to-digital converter to settle
ᅠ // after the last reading:
ᅠ delay(10); ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ
}
ᅠ
Please complete your information below to login.
Sign In
Create New Account