Show Posts
Pages: 1 ... 42 43 [44] 45 46 ... 197
646  Topics / Robotics / Re: Detecting multiple keypresses in arduino processing on: January 02, 2014, 07:37:44 pm
Oh, your actually using the Processing IDE to read your keys then send them to your arduino.

Your code will look more like this. Link HERE
Code:
// Click on the window to give it focus,
// and press the 'B' key.

void draw() {
  if (keyPressed) {
    if (key == 'b' || key == 'B') {
      fill(0);
    }
  } else {
    fill(255);
  }
  rect(25, 25, 50, 50);
}
647  Topics / Robotics / Re: Detecting multiple keypresses in arduino processing on: January 02, 2014, 06:18:24 pm
Here is one example that just uses single key presses.
Code:
/*
simple control test
*/

volatile int gear = 150; //default speed First Gear

volatile char val;         // variable to receive data from the serial port

byte M1L = 3;              // PWM left drive motor
byte M2L = 5;              // PWM left drive motor
byte M1R = 9;              // PWM right drive motor
byte M2R = 6;              // PWM right drive motor
byte ledpin = 13;          // LED connected to pin 2 (on-board LED)

/*IMPORTANT*/
//M1 => High & M2 => Low: forward movement
//M1 => Low & M2 => High: Backward movement

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(M1L, OUTPUT);                               
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                               
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
 
  Serial.println("Commands, Press * to bring up help menu");
}

void loop() {
  if( Serial.available() )       // if data is available to read
  {
    digitalWrite(ledpin, HIGH);
    val = Serial.read();
    volatile int skewGear = gear/2;
    if(val == '1')
    {
      Serial.println("First Gear ");
      gear = 150;
    }
    else if (val == '2')
    {
      Serial.println("Second Gear ");
      gear = 200;
    }
    else if (val == '3')
    {
      Serial.println("Third Gear ");
      gear = 255;
    }


    if( val == 'W' || val == 'w' )//forwards               
    {
      Serial.println("Moving Forwards");
      //      Left Motor     :     Right Motor
      analogWrite(M1L, gear);
      analogWrite(M1R, gear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'S' || val == 's' )//backwards             
    {
      Serial.println("Moving Backwards");
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, gear);
      analogWrite(M2R, gear);                   
    }
    else if( val == 'A' || val == 'a' )//Left         
    {
      Serial.println("LEFT");
      digitalWrite(M1L, LOW);
      analogWrite(M1R, gear);
      analogWrite(M2L, gear);
      digitalWrite(M2R, LOW);                     
    }
    else if( val == 'D' || val == 'd' )             
    {
      Serial.println("RIGHT");   
      analogWrite(M1L, gear);
      digitalWrite(M1R, LOW);
      digitalWrite(M2L, LOW);
      analogWrite(M2R, gear);                 
    }
    else if( val == 'T' || val == 't' )             
    {
      Serial.println("Skew Left Forward");   
      analogWrite(M1L, skewGear);
      analogWrite(M1R, gear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'Y' || val == 'y' )             
    {
      Serial.println("Skew Right Forward"); 
      analogWrite(M1L, gear);
      analogWrite(M1R, skewGear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'G' || val == 'g' )             
    {
      Serial.println("Skew Left Backward");   
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, skewGear);
      analogWrite(M2R, gear);                 
    }
    else if( val == 'H' || val == 'h' )             
    {
      Serial.println("Skew Right Backward");   
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, gear);
      analogWrite(M2R, skewGear);                 
    }
    else if(val == ' ' || val == 'x' || val == 'X'){ 
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);
    }
    else if(val == '*'){
      Help();
    }   
  }
  else{
    digitalWrite(ledpin, LOW);
  }
}

void Help() {
  Serial.println("W = Forward");
  Serial.println("S = Backward");
  Serial.println("A = Left");
  Serial.println("D = Right");
  Serial.println("T = Skew Forward Left");
  Serial.println("Y = Skew Forward Right");
  Serial.println("G = Skew Backward Left");
  Serial.println("H = Skew Backward Right");
  Serial.println("Space Bar = All stop");
  return;
}

Im working on the multiple key press code.
648  Using Arduino / Programming Questions / Re: Touchscreen TFT 2.8, need help on: January 02, 2014, 01:38:56 pm
Jasmine2501:

Here is a simple TFT keypad password sketch I made. I know you are not using my same library, so it most likely would not compile, but it should give you some idea as to how it will look.
Code:
#include <Wire.h>
#include <ITDB02_Touch.h>
#include <ITDB02_Graph16.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);  //myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02_Touch  myTouch(13,10,11,12,A4);

char * text[4][3] = {
  {
    "1","2","3"  }
  ,
  {
    "4","5","6"  }
  ,
  {
    "7","8","9"  }
  ,
  {
    "*","0","#"  }
};

char Pass[5];
char master[5] = "1111";
int Pcount=0;
int XC,YC;
int PassCounter=0;
byte orient = LANDSCAPE;

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_EXTREME);
  for(int line = 0; line <= 239; line++) // custom background color
  {
    myGLCD.setColor(0, 0, line);//  blue to black
    myGLCD.drawLine(0, line, 319, line);
  }
  PassWord_makeButton();
  PassWord_buttonText();
  //RUN();
}

void loop()
{
  myTouch.read();
  int tx = myTouch.TP_X;
  int ty = myTouch.TP_Y;
  XC= constrain (map(tx, 205, 3900,0,239),0,239);
  YC= constrain (map(ty, 300, 3850,0,319),0,319);
  GetNum(XC,YC);
}

void RUN()
{
  //  while(1) // Not using the Loop() function,
  //  {
  //    myTouch.read();
  //    int tx = myTouch.TP_X;
  //    int ty = myTouch.TP_Y;
  //    XC= constrain (map(tx, 205, 3900,0,239),0,239);
  //    YC= constrain (map(ty, 300, 3850,0,319),0,319);
  //    GetNum(XC,YC);
  //  }
}

void PassWord_makeButton()
{
  for(int y = 0; y < 300;y+=100)
  {
    for(int x = 0; x < 200; x+=50)
    {
      drawButton(20+x,90+y,50+x,30+y); // this will draw the button on the screen by so many pixels
    }
  }
  return;
}

void drawButton(int x1, int y1,int x2, int y2)
{
  myGLCD.setColor(170,170,170); // grey
  myGLCD.fillRoundRect(y1-3, x1+3, y2-3, x2+3);//Button Shading 

  myGLCD.setColor(255, 255, 255); // white
  myGLCD.fillRoundRect(y1, x1, y2, x2);// outter button color

  myGLCD.setColor(200,0,0); // red
  myGLCD.fillRoundRect(y1-5, x1+5, y2+5, x2-5);//inner button color
  return;
}

void PassWord_buttonText()
{
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(200, 0, 0);
  myGLCD.setColor(255,255,255);
  for(int tr = 0; tr < 300; tr+=100)
  {
    for(int tc = 0; tc < 200; tc+=50)
    {
      char *myText = text[tc/50][tr/100];
      myGLCD.print(myText,52+tr,27+tc,0); //this will print the number into the center of the buttons
    }
  }
}

void GetNum(int tx,int ty) {
  char * lastText;
  for(int tr = 0; tr < 300; tr+=100)
  {
    for(int tc = 0; tc < 200; tc+=50)
    {
      char *myText = text[tc/50][tr/100];
      if(TouchButton((90+tr),(20+tc),(30+tr),(50+tc),XC,YC)) // this check to see if any of the buttons were pressed, then it sends the corresponding number to the "check" function
      {
        myGLCD.print(myText,0,1,0);
        check(*myText);
      }
    }
  }
}


void check(char pass) {
  myGLCD.setFont(BigFont);
  Pass[Pcount] = pass;  //store incoming numbers in an array
  myGLCD.printNumI(Pcount,200,0);
 
  if(Pcount == 3)// only when the array is filled, does it check the numbers
  {
    myGLCD.print(Pass,0 + 15*Pcount,220,0);
    if(!strcmp(Pass, master)){
      myGLCD.print("GOOD",130,0,0);
      delay(1000);
      myGLCD.print("    ",130,0,0);
    }
    else{
      myGLCD.print("FAIL",130,0,0);
      delay(1000);
      myGLCD.print("    ",130,0,0);
    }
  }

  delay(500);
  Pcount++;
  if(Pcount > 3) // this ensure the count does not exceed the maximum lenght of the password
  {
    Pcount = 0;
    PassCounter = 0;
  }
}

boolean TouchButton(int x1, int y1, int x2, int y2, int xc, int yc){
  if (orient==LANDSCAPE)
  {
    xc = xc ^ yc;
    yc = xc ^ yc;
    xc = xc ^ yc;
  }

  if (x1>x2)
  {
    x1 = x1 ^ x2;
    x2 = x1 ^ x2;
    x1 = x1 ^ x2;
  }
  if (y1>y2)
  {
    y1 = y1 ^ y2;
    y2 = y1 ^ y2;
    y1 = y1 ^ y2;
  }

  if(xc >= x1 && xc <= x2 && yc >= y1 && yc <= y2) return true;
  return false;
}
649  Using Arduino / Project Guidance / Re: touch screen buttons on: January 01, 2014, 11:27:22 pm
Hi, maybe I can help.

myTouch.dataAvailable() This is a function from your UTouch library and what this function does is it returns the state of the screen, whether if or not it was touched. So if you touch the screen, it sets a flag to TRUE letting the user know that the screen has been touched somewhere. If not touch, it simply returns false.

Now what the creator wrote, "if (myTouch.dataAvailable() == true)" what this is saying is basically what I just said, the IF statement is looking for the returned value the "condition" to be TRUE. He could just as well as "if (myTouch.dataAvailable() )" and it would mean the exact same thing.

Now your error stated "pressed button not declared" this is saying that the variable pressed_button was not declaired, so a simple int pressed_button; declaired either globally or in the void loop function, should fix that.

650  Using Arduino / Project Guidance / Re: nRF24L01p+ PA+ LNA+ V3.1 help needed (RF Module) on: January 01, 2014, 04:48:47 pm
Its a transceiver rated with a 1000 meter range, Datasheet HERE. Its the same one I was going to get but it costs a lot of money.
651  Using Arduino / Programming Questions / Re: LCD help, please. (Noob to all this, patience is appreciated!) on: January 01, 2014, 04:43:23 pm
Quote
The error I am getting is:
"no matching function for call to 'LiquidCrystal_12C::LiquidCrystal_12C(int, int, int, int, int, int, int, int)'

Your LCD is using an I2C backpack, but "LiquidCrystal_12C(int, int, int, int, int, int, int, int)" indicates your not using the backpack, but instead just the screen. The error message is saying that no function with 8 elements exists, so If you look at the .h file in the LiquidCrystal_I2C library, you will see "LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);". To make it work, you need the I2C address of the screen, it's usually 0x27 or 0x20, and the number of columns and rows. For you it would be 16 , 2.

Here is what mine looks like,
LiquidCrystal_I2C lcd(0x20, 20, 4); // I am using a 20x4 LCD @ address 0x20
652  Using Arduino / Programming Questions / Re: 4 buttons problem. on: January 01, 2014, 03:38:26 pm
If  you just copied and pasted the sketch, then you need to add the closing parenthesis to these.

Quote
digitalWrite(ledPin1, (buttonState1 == HIGH);
  digitalWrite(ledPin2, (buttonState2 == HIGH);
  digitalWrite(ledPin3, (buttonState3== HIGH);
  digitalWrite(ledPin4, (buttonState4 == HIGH);
653  Using Arduino / Project Guidance / Re: radio shack tri color led strip-where is code on: January 01, 2014, 10:16:23 am
.ino is an arduino sketch file, so inorder to view the file, you need to download and install the arduino software.

K
654  Using Arduino / Programming Questions / Re: Translate C code - Help Needed on: December 31, 2013, 05:27:10 pm
Quote
#include <stdio.h>
#include "spa.h"  //include the SPA header file

Get rid of this whole thing
int main (int argc, char *argv[])                           
{    <= this too
    spa_data spa;  //declare the SPA structure
    int result;
    float min, sec;


spa_data spa;  //declare the SPA structure
int result;
float min, sec;

void setup()
{
 // if you need to set up any pins or other configurations
}

void loop()
{

    //enter required input values into SPA structure

    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
//.... rest of code below

One more thing I need to point out, printf, if you want to use the arduino Serial monitor, then in void setup(), add this line Serial.begin(9600) or what ever baud rate your want to use. And change all the "printf" to either Serial.print or Serial.println. Serial.print prints everything horizontally whereas println make everything vertically. ( new line)
655  Using Arduino / Programming Questions / Re: Touchscreen TFT 2.8, need help on: December 31, 2013, 05:20:22 pm
Try one of these.

SSD1289   = 16BIT @ 240x320
ILI9325C  = 8BIT @ 240x320
HX8340B_8 = 8BIT @ 180x220
656  Using Arduino / Programming Questions / Re: Touchscreen TFT 2.8, need help on: December 31, 2013, 11:10:51 am
What is your screen resolution 240x320 or smaller?
657  Using Arduino / Project Guidance / Re: lcd not declared on: December 31, 2013, 05:43:33 am
If by shield you mean a backpack then yes, you will need to use the I2C library. But again we don't know what kind of lcd you have so we can't be certain which library is right to use.
658  Using Arduino / Project Guidance / Re: Max simultaneous key presses for Keyboard library on: December 31, 2013, 05:41:26 am
First, you will need to get an Arduino Leonardo as it can act as a functional keyboard. Second, I don't know how many simultaneous key presses it can record, in fact I don't think it even sends out simultaneous key presses at all. From what I read, it sends the key presses one key at a time, so it's possible it can send any amount of key presses. However I don't have an Arduino Leonardo myself , so I can't do any tests to confirm this. Maybe another member can do a test and share the results.
659  Using Arduino / Project Guidance / Re: Max simultaneous key presses for Keyboard library on: December 31, 2013, 05:13:37 am
Instead of using the keyboard library, why not just adapt the SNES controller library? It reads each button as a bit and stores it into two bytes. This allows all the buttons to be pressed, but I'm not sure if it can distinguish multiple controllers. That you may need to look into.
660  Using Arduino / Project Guidance / Re: RS485 Phantom Power on: December 31, 2013, 05:07:49 am
Well you could have two of the wires be power lines, and the other one be a data line. The only issue with this method is the clock. All the clocks will need to be in sync otherwise you will get wrong data. However, if you can  maybe change the cable from a XLR to maybe a 3 Channel 1/8 or 1/4 inch audio jack, this way you can have the two power lines and a data + clock lines. If that is not an option then look at this site. Lowes_cables
Pages: 1 ... 42 43 [44] 45 46 ... 197