Go Down

Topic: Communication between LEDs (Read 1 time) previous topic - next topic

haukmoon269

So, i am trying to figure out how to make two LEDs communicate with each other. More specifically, when one LED(1) is turned on, the other LED(2) will turn on, and when the LED(1) shuts off, the other LED(2) will also turn off.

Code: [Select]
// ARDUINO

//TOUCH SENSING BETA - LED TURNS ON WHEN LIGHT IS PRESENT
//BY: RICARDO DE LEMOS 1/17/2007
int led1 = 13;
int cath = 2; // negative
int ando = 3;  // positive

void setup()
{
 pinMode(led1, OUTPUT);
 pinMode(cath, OUTPUT);
 pinMode(ando, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 //REVERSE BIAS
 digitalWrite(cath, HIGH);
 digitalWrite(ando, LOW);
 //CHARGE LED
 delay(6);
 //READ LED CAP
 pinMode(ando, INPUT);
 delay(6);
 //WRITE TO LED
 if (digitalRead(ando) == LOW)
 {
   digitalWrite(led1,HIGH);
 }
 else
 {
   digitalWrite(led1,LOW);
 }
 //RESET
 pinMode(ando, OUTPUT);
}

And the translated version for Processing.

//Processing


//biblio

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

//variabler

int turnOnLED = 13;

int sensorP = 3;

int sensorN = 2;

//setups

void setup(){

size (500,500);

println(Arduino.list());

arduino = new Arduino(this, Arduino.list()[0], 9600);

arduino.pinMode(turnOnLED, Arduino.OUTPUT);

arduino.pinMode(sensorP, Arduino.OUTPUT);

arduino.pinMode(sensorN, Arduino.OUTPUT);

}

//drawing

void draw(){
//charging LED
arduino.pinMode(sensorP, Arduino.OUTPUT);
arduino.digitalWrite(sensorN, Arduino.LOW);
arduino.digitalWrite(sensorP, Arduino.HIGH);

delay(6);
arduino.pinMode(sensorP, Arduino.INPUT);
if(arduino.digitalRead(sensorP) == Arduino.LOW){
  background(255);
}
println((arduino.digitalRead(sensorP)));
println((arduino.digitalRead(sensorN)));
}


does this code look right?

also, is there any specific way of actually building this? Any links or suggestions would be very helpful

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

haukmoon269

#2
Dec 03, 2009, 04:04 pm Last Edit: Dec 03, 2009, 04:06 pm by haukmoon269 Reason: 1
yes i did look at this, but i was hoping for some other form of references...

i think there is an issue with the code....

i'm not exactly sure what

AWOL

It may be that the "digitalWrite" and "pinMode" routines are taking too long, so you're missing the conditions you're looking for - you may have to resort to direct port manipulation.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike


haukmoon269

how can i approach this?

I am tempted to just fix up the digital write somehow so that when the one LED on pin 13 is on and the other LED detects it, it will go on. I wish i was more code-savvy

Grumpy_Mike

Do you actually need to use the LED as a sensor and emitter. If not then use a normal photo sensor as LEDs while they will work are not at their most reliable doing this.

haukmoon269

#7
Dec 03, 2009, 06:35 pm Last Edit: Dec 03, 2009, 06:52 pm by haukmoon269 Reason: 1
for this experiment I'm trying, yes i do want to use LEDs...I just want to see the many things i can do with this..

but anyways, in the code, i see there is Cathode and Anode, which i assume mean the anode and cathode of an LED? would it be possible if i manipulated those to do what i want?

i found something on youtube that reflects about the same idea of what i would like to do: http://www.youtube.com/user/randomskk


Grumpy_Mike

#8
Dec 04, 2009, 10:01 am Last Edit: Dec 04, 2009, 10:02 am by Grumpy_Mike Reason: 1
Quote
would it be possible if i manipulated those to do what i want?

Yes that is what that page was showing you.

haukmoon269

alrighty

so i think ill take this one step at a time:

my first goal would be to have the LED turn on whenever an accelerometer on the board is moved to a certain threshold.

i already made the code for it which i have here:
Code: [Select]
/*
   Memsic2125
   
   Read the Memsic 2125 two-axis accelerometer.  Converts the
   pulses output by the 2125 into milli-g's (1/1000 of earth's
   gravity) and prints them over the serial connection to the
   computer.
   
   The circuit:
      * X output of accelerometer to digital pin 2
      * Y output of accelerometer to digital pin 3
      * +V of accelerometer to +5V
      * GND of accelerometer to ground
 
   http://www.arduino.cc/en/Tutorial/Memsic2125
   
   created 6 Nov 2008
   by David A. Mellis
   modified 30 Jun 2009
   by Tom Igoe
 */
// these constants won't change:
const int xPin = 2;            // X output of the accelerometer
const int yPin = 3;            // Y output of the accelerometer
int LEDpin = 13;   //LED connected to digital pin 13
int thresholdx= 100;
int thresholdy= 100;
// variables to read the pulse widths:
  int pulseX, pulseY;
  // variables to contain the resulting accelerations
  int accelerationX, accelerationY;
void setup() {
  // initialize serial communications:
  Serial.begin(9600);
  // initialize the pins connected to the accelerometer
  // as inputs:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(LEDpin, OUTPUT);
  // variables to read the pulse widths:
  int pulseX, pulseY;
  // variables to contain the resulting accelerations
  int accelerationX, accelerationY;
  // read pulse from x- and y-axes:
}
void loop() {
 
  // read pulse from x- and y-axes:
  pulseX = pulseIn(xPin,HIGH);  
  pulseY = pulseIn(yPin,HIGH);
  // convert the pulse width into acceleration
  // accelerationX and accelerationY are in milli-g's:
  // earth's gravity is 1000 milli-g's, or 1g.
  accelerationX = ((pulseX / 10) - 500) * 8;
  accelerationY = ((pulseY / 10) - 500) * 8;
 
  if (accelerationX >thresholdx)
  digitalWrite(LEDpin, HIGH);
  else digitalWrite(LEDpin, LOW);
 
  if (accelerationY > thresholdy)
  digitalWrite(LEDpin, HIGH);
  else digitalWrite(LEDpin, LOW);
  // print the acceleration
  Serial.print(accelerationX);
  // print a tab character:
  Serial.print("\t");
  Serial.print(accelerationY);
  Serial.println();
  delay(100);
}


hopefully this is correct

Grumpy_Mike

Quote
hopefully this is correct


You tell us, you have the hardware, does it work as expected?

haukmoon269

alright an update

the code is correct! Whenever i turn the circuit board containing the accelerometer sideways, the LED lights up!

Go Up