Show Posts
Pages: 1 ... 50 51 [52] 53 54 ... 251
766  Using Arduino / Project Guidance / Re: Simple code moving forward on: May 05, 2014, 07:32:39 pm
Delays block the code from doing anything else until they are done, so I would highly recommend you take the delays out and take a look at the example sketch Blink Without Delay. Learn how that sketch works and incorporate it into your code.

Quote
We wrote some complicated code and it did not work at all.
Exactly what didn't work? You can also use the serial monitor to see your distance readings and other values to see where the problem(s) occur.
767  Using Arduino / Project Guidance / Re: Speed measurement (Help Please) on: May 05, 2014, 03:48:29 pm
Your IF statements don't make a whole lot of sense. I see what your doing in the first two but what about the last two?

Here is my method that is accurate to 120 MPH
Code:
#define FPS_to_MPH 0.68182 // scale factor
#define DISTANCE 35.5625 // distance between the two sensors or gates in feet.

const byte SensorOnePin = 2;
const byte SensorTwoPin = 3;

byte SensorOneState;
byte SensorTwoState;
float Speed = 0, MPH = 0, tmp = 0;
boolean GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  pinMode(SensorOnePin, INPUT);
  pinMode(SensorTwoPin, INPUT);
}

void loop()
{
  // This is using normal buttons to detect car passing through one gate to another,
  // this can be changed to use US sensors to replace the buttons. That part you will  
  // need to write yourself.
  
  SensorOneState = digitalRead(SensorOnePin);
  SensorTwoState = digitalRead(SensorTwoPin);

  if(SensorOneState && GotSecondSensor == false)  // car drives through first gate "sensor"
  {
    SensorOne_timer = millis(); // record time
    GotSecondSensor = true; // lockout this IF statement and unlock the next IF statement
  }
  
  if(SensorTwoState && GotSecondSensor == true)
  {
    SensorTwo_timer = millis(); //record the time the car reaches the second gate
    Speed = GetSpeed(SensorOne_timer, SensorTwo_timer, DISTANCE); // send the times and the distance into the function.
    Serial.print("MPH: ");
    Serial.println(Speed);
    GotSecondSensor = false; // unlock first IF statement and lockout this IF statement.
  }
}

float GetSpeed(unsigned long T1, unsigned long T2, float distance)
{
  MPH = distance * (FPS_to_MPH); // "(FPS_to_MPH)" -> conversion factor, feet per second to miles per hour
  tmp = (T2 - T1)/1000.00; // since the time we are using is in milliseconds, we need to convert milliseconds to seconds
  Serial.print("Time (seconds): ");
  Serial.println(tmp);
  return (MPH / tmp); //return the speed of the car in MPH
}
768  Using Arduino / Programming Questions / Re: Number Input, Calculator Style on: May 05, 2014, 02:43:02 pm
This might help.
Code:
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,20,4);

long first = 0;
long second = 0;
long total = 0;
double Ftotal = 0;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {
    '1','2','3','+'}
  ,
  {
    '4','5','6','-'}
  ,
  {
    '7','8','9','*'}
  ,
  {
    'C','0','=','/'}
};
byte rowPins[ROWS] = {
  2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  11,10,9,8}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup(){
  lcd.init();                      // initialize the lcd
  lcd.backlight();
}

void loop(){
  customKey = customKeypad.getKey();
  switch(customKey)
  {
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,0);
    first = (first * 10) + (customKey - '0'); // This method is how you combine all the key presses into one value.
    // (customKey - '0') -> converts the keypad character to integer
    lcd.print(first);
    break;

  case '+':
    lcd.setCursor(0,1);
    lcd.print("+");
    second = SecondNumber(); // get the collected the second number
    total = first + second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0; // reset values back to zero for next use
    break;

  case '-':
    lcd.setCursor(0,1);
    lcd.print("-");
    second = SecondNumber();
    total = first - second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0;
    break;

  case '*':
    lcd.setCursor(0,1);
    lcd.print("*");
    second = SecondNumber();
    total = first * second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0;
    break;

  case '/':
    lcd.setCursor(0,1);
    lcd.print("/");
    second = SecondNumber();
    lcd.setCursor(0,3);
    second == 0 ?
      lcd.print("Invalid")
     :
      Ftotal = (float)first / (float)second;
    lcd.print(Ftotal);
    first = 0, second = 0;
    break;

  case 'C':
    lcd.clear();
    break;
  }
}

long SecondNumber(){
  while( 1 )
  {
    customKey = customKeypad.getKey();
    if(customKey >= '0' && customKey <= '9')
    {
      second = (second * 10) + (customKey - '0');
      lcd.setCursor(0,2);
      lcd.print(second);
    }

    if(customKey == '=') break;  //return second;
  }
 return second;
}


769  Using Arduino / Project Guidance / Re: Need help for my arduino project PLEASE ANYONE! on: May 05, 2014, 11:48:19 am
Quote
the lasers that are dimming out
What are you using to power the lasers, the arduino or an external power supply? You should get one of these, they are called super batteries and they can keep a charge for a very long time. There are also 3 different sizes but the 1800 mAh should be more than enough for your project.

Since shipping will take a while and you need the power to finish you project, look around your house for a power adapter that can fit into the arduino power jack and be able to output 7 - 11 volts @ 600 mA - 1A. This should hold you over until you are able to get a proper power supply or that battery.

Also since the last time you posted, what have you changed in your code? Were you able to get the MAX7219 shift register?

Post your up-to-date code please.
770  Using Arduino / Programming Questions / Re: Setting multiple pins on or off using 1 line of code on: May 05, 2014, 10:54:24 am
You can take a look at Direct Port Manipulation
771  Using Arduino / Programming Questions / Re: Batt meter on: May 04, 2014, 11:39:49 pm
You could try and replace the map function with this and see if the values are any better.
Code:
double D_map(double data, double in_min, double in_max, double out_min, double out_max)//Map double
{
  return (data - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
772  Using Arduino / Programming Questions / Re: Self Moving Cart With Bluetooth on: May 04, 2014, 09:56:41 pm
Quote
would you happen to have an idea of how to reset the bluetooth?
Sorry, I dont know how and the spec sheet doesn't say either.
773  Using Arduino / Programming Questions / Re: Self Moving Cart With Bluetooth on: May 04, 2014, 09:36:49 pm
The range does not appear to be able to change.
774  Using Arduino / Programming Questions / Re: Self Moving Cart With Bluetooth on: May 04, 2014, 09:18:16 pm
I don't think that's possible, to lower the range. But then again I don't know what BT shield you have.
775  Using Arduino / Programming Questions / Re: Self Moving Cart With Bluetooth on: May 04, 2014, 08:50:47 pm
You can debug your code using the serial monitor and see what values you are getting for distance and distance1. I highly recommend you change your code to use the NewPing library, it is far more accurate and it makes getting data from multiple sensor very easy.
776  Using Arduino / Programming Questions / Re: Self Moving Cart With Bluetooth on: May 04, 2014, 07:45:10 pm
"I'm stuck somewhere" doesn't really help us. Where are you stuck, and with what? I see your using the old method of reading a distance. Look into using the NewPing library, it will help you a lot and it will be easier for us to read your code. You also don't need that 500 millisecond delay in your loop, but if you do then also look into the Blink without delay example sketch.
777  Development / Other Software Development / VirtualWire ID on: May 04, 2014, 04:28:12 pm
This is a new simple library I made to allow someone to individually control multiple devices on the same frequency.

Constructor:
  VWID( char );
 
Data handlers:
  (void) transmit( char * );
  (boolean) receive(uint8_t * );

If anyone has multiple RF modules of the same frequency, let me know what you think of the library.

Is it helpful enough to add it to the playground?
778  Using Arduino / Programming Questions / Re: Nested If and arrays on: May 04, 2014, 12:26:21 am
I'm not really surprised it's not working. Lets break down your snippet.
Quote
// Say Contador is set to zero (0) and readString == "ON1" and SetRoutine == 0.
if (readString == "ON1")
{
       if (SetRoutine ==0)
       {
         Contador++; // Contador (0) + 1 = 1.
         digitalWrite(LED1, HIGH);
         Memoria[Contador] = 10; Memoria[ 1 ] = 10;
       }

Now say readString == "ON1" again and SetRoutine == 1
       if (SetRoutine == 1)
       {
         Contador++; (1) + 1 = 2
         digitalWrite(LED1, HIGH);
         Comparador[Contador] = 10; // Comparador[ 2 ] = 10;  
         if(Memoria[1] == Comparador[1]) // Memoria[ 1 ] = 10 and  Comparador[ 1 ] = NULL
         {
           a = 5;
         }
       }
}

These two will never be equal unless you reset Contador back to zero or have your code like this "if(Memoria[1] == Comparador[2])" instead.
779  Using Arduino / Programming Questions / Re: XOR and XNOR operations with 2 or 3 inputs on: May 02, 2014, 06:55:10 pm
Why not make them into macros?

Code:
#define XOR(a, b) boolean(a != b ? 1 : 0)
#define XNOR(a, b) boolean(a != b ? 0 : 1)

void setup(){
Serial.begin(115200);
delay(1);
Serial.println("XOR");
Serial.println(XOR(0,0));
Serial.println(XOR(0,1));
Serial.println(XOR(1,0));
Serial.println(XOR(1,1));
Serial.println("XNOR");
Serial.println(XNOR(0,0));
Serial.println(XNOR(0,1));
Serial.println(XNOR(1,0));
Serial.println(XNOR(1,1));
}

void loop() {
 
}

For multiple inputs, you can do this XNOR(x, XNOR(y, z));
780  Using Arduino / Project Guidance / Re: Light up stairs as you walk, need sensor advice on: May 02, 2014, 05:40:06 pm
Yea, those will work perfectly.
Pages: 1 ... 50 51 [52] 53 54 ... 251