Pages: [1]   Go Down
Author Topic: arduino send 2 or more digital READ inputs to processing  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
Monterrey, MX
Offline Offline
Newbie
*
Karma: 0
Posts: 15
stay thinking @ growing up
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Experts of the universe!!!!!!!!

I want to calc the speed of a rim bike, I have a code found in www.cadjunkie.com thanks works perfect, but only for one rim/bike
it reads a magnetic sensor each time were the magnet pass through the sensor (default open) and close the circuit, so the code calc the time in miliseconds and send by serial.write function to processing...
then, processing reads each "step" or delay between pulses and make all graphs and work..

the issue here is I wanna read differents rims speeds at the same time, so I need 2 digital read inputs to send the info by serial write function to processing, and in processing use the values of rim1 and rim2


right now, I think than the hard problem is in arduino, but maybe the clue is in the method of how to read the info in processing, but I don't have idea of how to do this or if there are other way than could work,


if someone can give me a little help,  I will be greatfully


the code than i'm using in arduino is:

Code:
//credits to Adam of cadjunkie.com project
//

#define LED 13     //pin for the LED
#define SWITCH 0   //input for REED SWITCH

int val = 0;                     //used to store input value
int previousVal = 0;             //lets not be too repetitious
unsigned long time = 0;          // the last time the output pin was toggled
long debounce = 10;              // the debounce time, increase if the output flickers

void setup() {
 pinMode(LED, OUTPUT);   //tell arduino LED is an output
 pinMode(SWITCH, INPUT);   //SWITCH is input
 Serial.begin(9600);
}

void loop(){
 val=digitalRead(SWITCH);   //read input value and store it
 
 //check whether input is HIGH (switch closed)
 if (val==HIGH) {
   digitalWrite(LED, HIGH);   //turn LED on
   if (previousVal != HIGH) Serial.write( byte(1)); //old versions of arduino must use this: Serial.print(1, BYTE)
   previousVal = HIGH;
 } else{
   digitalWrite(LED, LOW);
   if (previousVal != LOW && millis() - time > debounce) Serial.write( byte(0));
   previousVal = LOW;
   time = millis();   
 }
}
Logged

Todo lo que no es posible imaginar, no es posible realizarlo.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26331
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

double up for 2 rims
Code:
//credits to Adam of cadjunkie.com project
// doubled up for 2 switches by CrossRoads

#define LED 13     //pin for the LED
#define SWITCH 0   //input for REED SWITCH

#define LED1 14     //pin for the LED
#define SWITCH1 2   //input for REED SWITCH

int val = 0;                     //used to store input value
int previousVal = 0;             //lets not be too repetitious
unsigned long time = 0;          // the last time the output pin was toggled
long debounce = 10;              // the debounce time, increase if the output flickers

int val1 = 0;                     //used to store input value
int previousVal1 = 0;             //lets not be too repetitious
unsigned long time1 = 0;          // the last time the output pin was toggled
long debounce1 = 10;              // the debounce time, increase if the output flickers

void setup() {
  pinMode(LED, OUTPUT);   //tell arduino LED is an output
  pinMode(SWITCH, INPUT);   //SWITCH is input

  pinMode(LED1, OUTPUT);   //tell arduino LED is an output
  pinMode(SWITCH1, INPUT);   //SWITCH is input

  Serial.begin(9600);
}

void loop(){
  val=digitalRead(SWITCH);   //read input value and store it
  val1=digitalRead(SWITCH1);   //read input value and store it

  //check whether input is HIGH (switch closed)
  if (val==HIGH) {
    digitalWrite(LED, HIGH);   //turn LED on
    if (previousVal != HIGH) Serial.write( byte(1)); //old versions of arduino must use this: Serial.print(1, BYTE)
    previousVal = HIGH;
  }
  else{
    digitalWrite(LED, LOW);
    if (previousVal != LOW && millis() - time > debounce) Serial.write( byte(0));
    previousVal = LOW;
    time = millis();   
  }
  // 2nd switch
  if (val1==HIGH) {
    digitalWrite(LED1, HIGH);   //turn LED on
    if (previousVal1 != HIGH) Serial.write( byte(9)); //  use upper 2bits 0x80
    previousVal1 = HIGH;
  }
  else{
    digitalWrite(LED1, LOW);
    if (previousVal1 != LOW && millis() - time1 > debounce1) Serial.write( byte(4)); //  use upper 2bits 0x40
    previousVal1 = LOW;
    time1 = millis();   
  }
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: