Pages: [1]   Go Down
Author Topic: Binary Input Signal  (Read 1225 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys,

I've been working with a QT-1080 sensor which has a binary output mode. It uses 3 pins for the first 3 binary numbers and a detect pin, that fires upon any contact, to make 8 combinations possible. I want to do a simple thing: light up LED's that correspond to each of the 8 touch channels.

I'm very new to arduino, so can somebody tell if this code makes any sense? or if I'm overloading the arduino with unnecessary commands?

Thanks in advance

Code:
int binPin1 = 12; //Inputs
int binPin2 = 11;
int binPin4 = 10;
int detPin = 13;

int ledPin1 = 9; //Outputs
int ledPin2 = 8;
int ledPin3 = 7;
int ledPin4 = 6;
int ledPin5 = 5;
int ledPin6 = 4;
int ledPin7 = 3;
int ledPin8 = 2;

int bin1 = 0;                    // variable for reading the pin status
int bin2 = 0;                    // variable for reading the pin status
int bin4 = 0;                    // variable for reading the pin status
int det = 0;                    // variable for reading the pin status

void setup() {
  pinMode(binPin1, INPUT);
  pinMode(binPin2, INPUT);
  pinMode(binPin4, INPUT);
  pinMode(detPin, INPUT);
  
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  
}

void loop(){
  bin1 = digitalRead(binPin1);  // read input value
  bin2 = digitalRead(binPin2);  // read input value
  bin4 = digitalRead(binPin4);  // read input value
  det = digitalRead(detPin);  // read input value
  
 if (det == HIGH) {
   if (bin4 == HIGH) {
     if (bin2 == HIGH) {
       if (bin1 == HIGH) {
         digitalWrite (ledPin8, HIGH);
       } else { //bin1 == LOW
         digitalWrite (ledPin7, HIGH);
       }      
     } else { //bin2 == LOW
       if (bin1 == HIGH) {
         digitalWrite (ledPin6, HIGH);
       } else { //bin1 == LOW
         digitalWrite (ledPin5, HIGH);
       }  
     }
   } else { //bin4 == LOW
     if (bin2 == HIGH) {
       if (bin1 == HIGH) {
         digitalWrite (ledPin4, HIGH);
       } else { //bin1 == LOW
         digitalWrite (ledPin3, HIGH);
       }      
     } else { //bin2 == LOW
       if (bin1 == HIGH) {
         digitalWrite (ledPin2, HIGH);
       } else { //bin1 == LOW
         digitalWrite (ledPin1, HIGH);
       }  
     }
   }
    
 } else {
   digitalWrite(ledPin1, LOW);
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
   digitalWrite(ledPin4, LOW);
   digitalWrite(ledPin5, LOW);
   digitalWrite(ledPin6, LOW);
   digitalWrite(ledPin7, LOW);
   digitalWrite(ledPin8, LOW);  
 }
                
}
« Last Edit: June 28, 2007, 02:16:03 am by GuusT » Logged

Pages: [1]   Go Up
Jump to: