Multiple input/outputs combined


edit: problem resolved, replaced newer, better problem!

hi, trying integrate 2 separate p controllers read different data , translate different responses, separately. 1 function reads current rpm ad adjusts throttle servo accordingly (powering small gas engine), other reads temperature @ (much longer) intervals , adjusts fuel/air mixture needed accordingly using continuous rotation servo. have gotten each 1 working independently, not together. have considered using 2 separate arduino boards, 1 important function of temperature monitor can send signal close throttle, if engine gets warm. means 1 arduino rule them all.

note: using hall effect sensor rpm, , spark fun thermocouple temperature readings. code has test parameters set in right don't have run engine test functionality.

at current time, serial output shows many rapid readings of temperature sensor @ startup, followed continuous rpm readings after no more temp readings. want see rpm reading every .5 seconds, , temp reading every 2.5 seconds (or in practice, 25 seconds).

i tried using modulo reset temperature count without using delay(25000) impossible keep reading rpm time , adjusting throttle.

any appreciated. have studies blink without delay , thought best way of doing things. working alternative ideas super great;

code: [select]
volatile byte half_revolutions;
 unsigned int rpm;
 unsigned long timeold;

#include <servo.h>
#include <sparkfunmax31855k.h> // using max31855k driver
#include <spi.h>  // included here due arduino ide; used in above header
#include <servo.h>
servo traxxas;  // create traxxas object control throttle
servo ls; // create ls object control hsn
// define spi arduino pin numbers (arduino pro mini)
int throttle; // variable throttle object

int t = 71; // create variable throttle pos tra2055
 
const uint8_t chip_select_pin = 10; // using standard cs line (ss)
// sck & miso defined arduiino
const uint8_t vcc = 14; // powering board straight arduino pro mini
const uint8_t gnd = 15;
int hsn; //variable high speed needle position object
int n = 92; // create neutral position ls-3006
// instantiate instance of sparkfunmax31855k class
sparkfunmax31855k probe(chip_select_pin, vcc, gnd);

const int delaytemp = 2500; //sets delay temp sensing ~pwal

void setup()
{
  // put setup code here, run once:
  serial.begin(9600);
  attachinterrupt(0, magnet_detect, rising); //initialize intterrupt pin (arduino digital pin 2)
  half_revolutions = 0;
  rpm = 0;
  timeold = 0;
  traxxas.attach(3);  // attaches traxxas tra2055 servo on pin 9 throttle object
  ls.attach(10); //attaches ls-2006 servo on pin 10 hsn object
  serial.println("\nbeginning...");
  delay(50);  // let ic stabilize or first readings garbage
}

void loop(){
  // uses modulo opperator program can see if time multiple of temp reading delay , runs temp function
  if(delaytemp % millis() == 0) {
    float temperature = probe.readtempf();
    if(!isnan(temperature)) {
        serial.print("\ttemp[f]=");
        serial.println(temperature);
        //190
        if (temperature < 70){
          hsn = n;
          ls.write(hsn);
       }
        //190 240
       else if(temperature >= 70 && temperature < 80){
          hsn = 100;
          ls.write(hsn);
          delay(330);
          hsn = n;
          ls.write(hsn);
        }
        //240 260
        else if(temperature >= 80 && temperature <= 90){
          hsn = n;
          ls.write(hsn);
        }
        //260 280
        else if(temperature > 90 && temperature <= 95){
        hsn = 83;
        ls.write(hsn);
        delay(330);
        hsn = n;
        ls.write(hsn);
        }
      //filler command. actual command: t = 76 shut throttle due overheat
      else {
        hsn = n;
        ls.write(hsn);
        t = 76;
        traxxas.write(throttle);
      }
    }
  }
  if(millis() - timeold == 500){
    rpm = 120 * half_revolutions;
    timeold = millis();
    half_revolutions = 0;
    serial.println(rpm,dec);
    throttle = t;
    traxxas.write(throttle);
    if(rpm <= 2500){
      t = 71;
    }
    else if(rpm > 2500 && rpm < 7900){
      t = t - .5;
    }
    else if(rpm >= 7900 && rpm <= 8100){
      t = t;
    }
    else if(rpm > 8100 && rpm < 12000){
      t = t + .5;
    }
    else{
      t = 76;
    }

     // ===================
     // loose block won't compile - these curly braces don't belong anything
     {
      t = min(t, 76); // sets throttle closed servo max position)
      t = max(t, 50); // sers throotle open servo max position)
     }
    // ===================
     }
}

//this function called whenever magnet/interrupt detected arduino
void magnet_detect(){
   half_revolutions++;
   //serial.println("detect");
}


*hopefully, code posted time in code box.

close.  want looks like

[code]  paste code here. [/code]


Arduino Forum > Using Arduino > Programming Questions > Multiple input/outputs combined


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???