Show Posts
Pages: [1] 2 3 ... 197
1  Using Arduino / Project Guidance / Re: Servo programming on: Today at 07:21:30 pm
This part here is inside the IF statement and will only set the position back to 180 if your holding the button.
Quote
if ((pos == 0) || (pos < 0))
    {                             
      pos = 180;
      delay(5); // control speed to restart position
    }
What you need is to have a ELSE statement that tells the code what to do when you are not pressing the button or if you press then release the button.

Look into State machines.
2  Using Arduino / Project Guidance / Re: Servo programming on: Today at 12:57:07 pm
Quote
if(digitalRead(leftPin) == HIGH)
Where is the else statement telling the servo to move the other way?
3  Using Arduino / Programming Questions / Re: the output pins are not effected by serial reading on: Today at 11:37:17 am
Quote
char angle = Serial.read();  // You're reading in one char at a time
.
.
if(angle >= 0 && angle <= 30) // but yet you are looking for an actual value.
.
else if(angle > 30 && angle <= 90)

You should write a function or something that gets one or two chars and converts them into the values you want.
4  Using Arduino / Programming Questions / Re: Getting 'setColor' was not delaired in this scope error on: Today at 01:14:10 am
Show me how you were able to use setColor to change the color of the LED. Post the code.
5  Using Arduino / Programming Questions / Re: Getting 'setColor' was not delaired in this scope error on: Today at 12:48:11 am
Is that the full code?
Are you using a normal RGB LED?

"setColor()" is part of a library (quite a few actually, most likely the LiquidCrystal library), so even though it is orange, it doesn't mean you can use it in your sketch like that.

What you need to use is the digitalWrite functions or analogWrite, if you want to have full control of the colors.

6  Using Arduino / Programming Questions / Re: Need help changing code to change display orientation on: April 18, 2014, 04:32:06 pm
There is a way to do it, but that would require rewriting the code.

Here is my function, if your interested.
Code:
byte* rotate90deg(byte data[]){ //private func
  Serial.println();
  for(int c=0;c<8;c++)
  {
    for(int r=0;r<8;r++)
    {
      tmpAry[r] <<= 1;
      tmpAry[r] |= bitRead(data[c],r);
      //Serial.println(tmpAry[r],BIN);
    }
    //Serial.println();
  }
  return tmpAry;
}

I don't have a 5*7 display to do any tests, so I can only go by the serial monitor. Sorry.

This is my method to rotate the array 0, 90, 180 and 270 degrees.
Code:
byte flip(byte ary)//private func
{
  static const byte table[16] = {
    0x0, 0x8, 0x4, 0xC,
    0x2, 0xA, 0x6, 0xE,
    0x1, 0x9, 0x5, 0xD,
    0x3, 0xB, 0x7, 0xF
  };
  byte h = table[(ary & 0xf0) >> 4];
  //Serial.println(h,HEX);
  byte l = table[ary & 0x0f] << 4;
  //Serial.println(l,HEX);
  return (l | h );
}

byte RotateData(byte data[], int rot){
  int cnt=0;
  //Serial.println(data,HEX);
  switch(rot)
  {
  case 0:
    display(data,0);
    break;

  case 90:
    display(rotate90deg(data),0); // 90
    break;

  case 180:
    display(data,1); // 180
    break;

  case 270:
    display(rotate90deg(data),1); // 270
    break;
  }
}

void display(byte *Ary, boolean Inv){
  for(byte k = 0; k < 8; k++)
  {
    if(Inv)
    {
      shiftOut(data,clock,MSBFIRST,8-k);
      shiftOut(data,clock,MSBFIRST, flip(Ary[k]));
    }
    else
    {
      shiftOut(data,clock,MSBFIRST,k+(byte)1);
      shiftOut(data,clock,MSBFIRST, Ary[k]); 
    }
    digitalWrite(load,LOW);
    digitalWrite(load,HIGH);
  }
  Serial.println();
}
7  Using Arduino / Programming Questions / Re: Wrong Data Sending on: April 18, 2014, 03:02:38 pm
Hmmm.
Quote
int thisChar

Why do you have delays in there? Take them out.
8  Using Arduino / Programming Questions / 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.
9  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.
10  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).
11  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
}
12  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
}
13  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.
14  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)
15  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.
Pages: [1] 2 3 ... 197