Show Posts
Pages: 1 ... 30 31 [32] 33 34 ... 227
466  Using Arduino / LEDs and Multiplexing / Re: Need help changing code to change display orientation on: April 18, 2014, 02:59:02 pm
Post your code. You can make a function that rotates the bytes 90* before showing them. I made a function that does just that but it is made to work with 8x8 displays. I don't think it will work on a 5x7.
467  Using Arduino / Programming Questions / Re: Need help with making a password circuit + writing code on: April 17, 2014, 07:03:37 pm
Now that you got it working, you can start making it more efficient.

If you want, you can make this part
Quote
key1State = digitalRead(key1);
  if (key1State == HIGH) {
    password.append('1');
    Serial.println("1");
  }
  key2State = digitalRead(key2);
  if (key2State == HIGH) {
    password.append('2');
    Serial.println("2");
  }
  key3State = digitalRead(key3);
  if (key3State == HIGH) {
    password.append('3');
    Serial.println("3");
  }
  key4State = digitalRead(key4);
  if (key4State == HIGH) {
    password.append('4');
    Serial.println("4");
  }
into a FOR loop. If the button is high, return the index.
Now this would mean you would need to reverse these,
Quote
const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;
so that all you would need to do is subtract 3 from the index to get what button was pressed.
468  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 17, 2014, 06:56:06 pm
With these type of modules, the masters are not able to connect to a PC, only the slaves can. I don't know why it's like that, but both of my master modules will not connect to my laptop, but my slave modules will almost instantly (after already paired).
469  Using Arduino / Project Guidance / Re: Count 18 lines and pause. on: April 16, 2014, 11:48:50 pm
EDIT:
To make things simpler for you us, this has gone on long enough.

Code:
void setup()
{
  Serial.begin(9600); // should really be set to 115200, but just this is just a demonstration of how FOR loops work.
}

void loop()
{
  for( byte i = 0; i < 10; i++)
  {
    Serial.println(i); // prints 0 - 9, per line
  }
  Serial.println("End of block);
  delay(5000); // Just so it gives you time to see the results, without them flashing across the screen
}
470  Using Arduino / Project Guidance / Re: Sport Bike Cluster on: April 16, 2014, 11:41:03 pm
What about maybe using a laser trip wire and your spokes? The beam breaks, record the time then once it passes the second spoke find the difference of the two times and get your speed that way.

I have a sketch you can use to get you going, for right now it uses tactile buttons to simulate a car passing through two gates that are 35 feet away from each other. All you would need to do is substitute the buttons for the sensor (you will need to modify the code a little since your using one sensor) and change the 35 feet to the distance between the two spokes.

Code:
#define FPS_to_MPH 0.68182 // scale factor
#define DISTANCE 35.5625 // distance between the two sensors or gates.

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
}
471  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 16, 2014, 11:16:50 pm
Try these.

Master:
Code:
void setup()
{
  Serial.begin(9600);
  delay(1);
  Serial.println("Transmitting");
}

void loop()
{
  Serial.print('H');
  delay(1000);
  Serial.print('L');
  delay(1000);
}

Slave: Keep in mind you will need to use Software serial if you want to use the Serial monitor, to see the received char.
Code:
char val; // variable to receive data from the serial port
int ledpin = 13; // LED connected to pin 13 (on-board LED)

void setup() {
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  Serial.begin(9600);       // start serial communication at 115200bps, must match the transmitting side
  delay(1);               // 1 millisecond delay between starting the serial communication and sending out a message
  Serial.println("Receiving");    
}

void loop()
{
  if( Serial.available() > 0)       //See if data is available to read
  {
    val = Serial.read();
    Serial.println(val);

    if( val == 'H' || val == 'h' )               // if 'H' was received
    {
      digitalWrite(ledpin, HIGH);  // turn ON the LED
    }
    if( val == 'L' || val == 'l' )
    {
      digitalWrite(ledpin, LOW);   // otherwise turn it OFF
    }
  }
}

Make sure the Serial monitor is set to 9600, otherwise you will see garbage in the terminal.

EDIT:
On second thought, they might need to be set to 9600, as per the default baud rate. I changed them.
472  Development / Other Software Development / Re: New TFT Extension Library on: April 16, 2014, 04:51:13 pm
I can make the rounded_square, maybe the moon, smiley faces, text-balloon, hourglass and music bar + notes.

The Greek, math and currency symbols would be easy to make if I could get into the original character table, but I'll try.

Do you want to hourglass to flip over?

Added:
Rounded_Square : DONE (with fill)
Moon + phases : DONE (also added craters)
Faces : DONE (9 types of eyes and 7 types of mouths. I also added preset combinations)
HourGlass : DONE (EDIT: Capable from 1 second to about 1 year, give or take a few hours; Or until the millis function rolls over and screws up the time. And NON Blocking);
473  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 09:23:01 pm
You would need to learn about the Bink Without Delay sketch and how it works.
474  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 15, 2014, 08:04:05 pm
Is the 3 still in double quotes, if so, you want to receive a char, so you need to send a char. Simply put, you need to use single quotes not double quotes.

Serial.print( '3' );

If you still get garbage, check your wiring. BT: Tx -> Ard: Rx and BT: Rx -> Ard: Tx
This needs to be done for both master and slave.
475  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 07:57:45 pm
I looked over your code and compared it to mine and it seems your missing this function.
ps2x.read_gamepad(false, 0);

Add that function in your loop().
476  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 05:27:43 pm
Quote
the values come back as expected so I doubt it is a wiring issue...
What values, the buttons?
Can you post a picture of your setup?
477  Using Arduino / Programming Questions / Re: very very important - help me on: April 15, 2014, 05:26:00 pm
You need to have the actual library in the correct place, and some photos of your wiring would be really helpful. Check out this post HERE.
478  Development / Other Software Development / Re: New TFT Extension Library on: April 15, 2014, 04:24:18 pm
I have three more functions on the way, two are already done and one i'm still working on.
The two that are done are drawArc and TouchArc.

drawArc(int cx, int cy, int radius, int start, int stop, int thickness, byte R, byte G, byte B);
Like my circle function, it needs a X/Y coordinate, a radius, and now it needs a start and stop angle, a thickness (will not exceed the radius value or below 0) and finally, a color.

TouchArc(int cx, int cy, int radius, int start, int stop, int thickness);
This function returns a percentage of where you touch the arc from right to left. 0  - 100%

And the last function is a Slider, it can either be horizontal or vertical, and it too will return the percentage of it's level.
It can be mapped to any size or thickness, and I must insist you use a stylist or something with a soft point.
479  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 15, 2014, 04:13:30 pm
Quote
I added the comma and it makes it much easier to read smiley-razz Is there a way I can tell it to kick the next set of values down to the next line on the serial monitor?
Yea, that was my fault, change the last one to Serial.println(Input2);

Quote
1501,1501,etc.
Is there something wrong with how I used/ setup the map function?
The joysticks work exactly like a potentiometer, so full up is 255 and full down is 0, so in between is 128, and when you map 128, that equals to ~1500. Those values should increase and decrease when you move the stick, if it doesn't then there may be a problem with the wiring or the controller itself.

How much voltage is the controller getting, 3.3 or 5V? I have a regular and a wireless controller and they only seem to work at 3.3V.
480  Using Arduino / Project Guidance / Re: Inconsistent values with Bluetooth and Serial.Read on: April 14, 2014, 11:37:06 pm
Make it Serial.print on the master side and a type char on the slave side.
Pages: 1 ... 30 31 [32] 33 34 ... 227