Loading...
  Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Project Guidance / Re: Power supply opto relay on: Today at 10:12:04 am
The Arduino needs about 5-9 volts of DC power at about 50mA with a large safety factor you should be able to find a wall wart that supplies a minimum of 500mA depending on your opto boards. But since I do not see any schematics it's hard to tell. you can just as easily attach a male barrel jack onto the wall wart and use that to provide power.
2  Using Arduino / Project Guidance / Re: ROTARY ENCODER CODE... on: Today at 12:09:49 am
It's easy, use the mills() function and count to 12,100,1024 etc however many counts per rotation the encoder is and save the number of mills() in a long variable. rotate it 360 again and subtract the two millis() and you  will get the time it took to complete one rotation.

3  Using Arduino / Project Guidance / 6 amp bipolar stepper motor driver on: May 18, 2013, 01:06:20 pm
What would be the most inexpensive way to drive several 6 amp 1.8 volt DC stepper motors with an Arduino?

Thanks
4  Using Arduino / Programming Questions / Re: Ports on the Arduino Mega Pins 22-53 on: April 22, 2013, 09:02:32 pm
Lefty,

I don't understand the spreadsheet I cannot find digital pins 22-53 on it.

Thanks

Bill
5  Using Arduino / Programming Questions / Ports on the Arduino Mega Pins 22-53 on: April 22, 2013, 05:25:50 pm
I need to turn digital pins 22-53 on the mega 2560 on and off really (really) fast. No inputs being processed just switching on Mux's how do I manipulate the ports to do this? I cannot find a good example.

Thank you
6  Using Arduino / Programming Questions / Re: array average on: April 22, 2013, 05:01:10 pm

float runningTotal = 0;
float average = 0;
for (int x = 0; x< 100; x++)
  {
   
    adcValue1= analogRead(phototransistorPin1);
    runningTotal = adcValue1 + runningTotal;
    adcValue2= analogRead(phototransistorPin2);
    runningTotal = adcValue1 + runningTotal;
    adcValue3= analogRead(phototransistorPin3);
    runningTotal = adcValue1 + runningTotal;
    adcValue4= analogRead(phototransistorPin4);
     
   average = runningTotal/x;
   
  }
7  Using Arduino / Displays / bitmap on 2.8" TFT touchscreen using memory alone on: April 22, 2013, 04:53:37 pm
I am using a mega 2560 with the 2.8" TFT touchscreen available on ADAFRUIT. I have 200,000 bytes left on the processor memory. Can I use this to display a bitmap image without using a scan disc card? If so how?

Thanks
8  Using Arduino / Programming Questions / Passing defined arrays into function, variables not declared in scope on: April 11, 2013, 08:37:24 pm
Greetings,

I am having a lot of trouble passing arrays into functions. It keeps telling me that the arrays are not defined. They are in the setup() could someone tell me why?

Here are the errors:
BareMinimum.cpp: In function 'void loop()':
BareMinimum:20: error: 'Block_1' was not declared in this scope
BareMinimum:20: error: 'Block_2' was not declared in this scope
BareMinimum:20: error: 'Block_3' was not declared in this scope
BareMinimum:20: error: 'Block_4' was not declared in this scope

Here is the code:
Code:
void setup() {
  // put your setup code here, to run once:

#define Block_Size 16

#define S3_pin 53
#define S2_pin 51
#define S1_pin 49
#define S0_pin 47


int Block_1[Block_Size];
int Block_2[Block_Size];
int Block_3[Block_Size];
int Block_4[Block_Size];

}

void loop() {
  // put your main code here, to run repeatedly:
  CheckBlocks(Block_1, Block_2, Block_3, Block_4);
 
 
 
 
}

void CheckBlocks(int Block_1[], int Block_2[], int Block_3[], int Block_4[]){
  int quadrent = 0;
  for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       delay(1);
       Block_1[channel] = analogRead(A15);
  }// End for loop
  quadrent = 1;
  for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       delay(1);
       Block_1[channel] = analogRead(A14);
  }// End for loop ;
  quadrent = 2;
  for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       delay(1);
       Block_1[channel] = analogRead(A13);
  }// End for loop );
  quadrent = 3;
  for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       delay(1);
       Block_1[channel] = analogRead(A12);
  }// End for loop
}//end function
 
 



//This function activates the muxes
void set_channel(int channel) {
     switch(channel)
       {
        case 0:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 1:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 2:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 3:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 4:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 5:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 6:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 7:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
       case 8:   digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 9:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 10: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 11: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH); 
                 break;
        case 12: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 13: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 14: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 15: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;       
        default: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);   
                 break;
                 }//end case
}//end function

9  Using Arduino / Programming Questions / Re: Passing and returning Arrays into functions on: April 09, 2013, 10:01:40 am
Thank you.

I understand now that I am suppost to give the compiler the size of the array via pointer. How do I output or return an array from a function?

Thanks

Bill
10  Using Arduino / Programming Questions / Passing and returning Arrays into functions on: April 08, 2013, 10:55:29 pm
I am trying to pass an array of binary numbers into a function and (eventually) have it return the updated array. I keep getting some errors I do not understand can someone tell me what to do? I have the function and inputs in the code (snippets where the errors are flagged) and the errors posted below

Cleverblocks_test_2.cpp: In function 'void loop()':
Cleverblocks_test_2:229: error: expected primary-expression before ']' token
Cleverblocks_test_2:229: error: expected primary-expression before ']' token
Cleverblocks_test_2:229: error: expected primary-expression before ']' token
Cleverblocks_test_2:229: error: expected primary-expression before ']' token
Cleverblocks_test_2.cpp: In function 'void CheckBlocks(int*, int*, int*, int*)':
Cleverblocks_test_2:257: error: expected primary-expression before ']' token
Cleverblocks_test_2:257: error: 'Bank1' was not declared in this scope
Cleverblocks_test_2:257: error: expected primary-expression before ']' token
Cleverblocks_test_2:259: error: expected primary-expression before ']' token
Cleverblocks_test_2:259: error: 'Bank2' was not declared in this scope
Cleverblocks_test_2:259: error: expected primary-expression before ']' token
Cleverblocks_test_2:261: error: expected primary-expression before ']' token
Cleverblocks_test_2:261: error: 'Bank3' was not declared in this scope
Cleverblocks_test_2:261: error: expected primary-expression before ']' token
Cleverblocks_test_2:263: error: expected primary-expression before ']' token
Cleverblocks_test_2:263: error: 'Bank4' was not declared in this scope
Cleverblocks_test_2:263: error: expected primary-expression before ']' token
Cleverblocks_test_2.cpp: In function 'int GetValues(int*, int)':
Cleverblocks_test_2:294: error: expected primary-expression before ']' token


Code:
void CheckBlocks(int Block_1[], int Block_2[], int Block_3[], int Block_4[]){
  int quadrent = 0;
  Block_1[] = GetValues(Bank1[], quadrent);
  quadrent = 1;
  Block_2[] = GetValues(Bank2[], quadrent);
  quadrent = 2;
  Block_3[] = GetValues(Bank3[], quadrent);
  quadrent = 3;
  Block_4[] = GetValues(Bank4[], quadrent);
}//end function
 
 


int GetValues(int Bank[], int quad){
    if (quadrent == 0){
      for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       int Analog_voltage = analogRead(A15);
       }//end for loop
       }// end if
    else if (quadrent == 1){
      for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       int Analog_voltage = analogRead(A14);
       }//end for loop
       }// end if
    else if (quadrent == 2){
      for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       int Analog_voltage = analogRead(A13);
       }//end for loop
       }// end if
    else {
      for(int channel= 0; channel < 16; channel++){
       set_channel(channel); // turns on channel
       int Analog_voltage = analogRead(A12);
       }//end for loop
       }// end if
       return Bank[];
}// end function

//timer1 interrupt 1Hz
ISR(TIMER5_COMPA_vect){
      for(int quadrent = 0; quadrent < 4; quadrent++){
       for(int channel= 0; channel < 16; channel++){
         
     }//second for loop
    }// first for loop 
 }//Interrupt

//This function activates the muxes
void set_channel(int channel) {
     switch(channel)
       {
        case 0:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 1:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 2:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 3:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 4:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 5:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 6:  digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
        case 7:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, LOW);
                 break;
       case 8:   digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 9:  digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 10: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 11: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, HIGH); 
                 break;
        case 12: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 13: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 14: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;
        case 15: digitalWrite(S0_pin, HIGH);
                 digitalWrite(S1_pin, HIGH);
                 digitalWrite(S2_pin, HIGH);
                 digitalWrite(S3_pin, HIGH);
                 break;       
        default: digitalWrite(S0_pin, LOW);
                 digitalWrite(S1_pin, LOW);
                 digitalWrite(S2_pin, LOW);
                 digitalWrite(S3_pin, LOW);   
                 break;
                 }//end case
}//end function


Thank you smiley
11  Using Arduino / Programming Questions / Using the MEGA's additional timers for interrupts on: April 07, 2013, 10:28:59 pm
Hello,

I am using a TFT touchscreen (Adafruit's one) and I am trying to implement a timer interrupt to run through several for loops once a second but the interrupts are (I think) being used for the touch screen. I am using the mega 2560 which has additional timers and I cannot figure out how to configure the timers to use them instead of timer0 timer1 timer2 which I believe the touch screen uses in the background. I am posting my code and the timers are included just below the header "Interrupts"

Please let me know what I need to change to use the additional timers in the MEGA
Code:
/*********************************************************************************************************
*                     Include Statements
/********************************************************************************************************/

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <Timer.h>

/*********************************************************************************************************
*                     Define Statements
/********************************************************************************************************/
#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

//The min and max pixels of touch screen
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


#define S3_pin 53
#define S2_pin 51
#define S1_pin 49
#define S0_pin 47

#define E0_pin 45
#define E1_pin 43
#define E2_pin 41
#define E4_pin 39

Adafruit_TFTLCD tft;

#define BOXSIZE   100



/*********************************************************************************************************
*                     Varaible Declaration Statements
/********************************************************************************************************/
int Isready = 0; // ready to start building
int screen = 0; // selects the screen
int Analog_voltage; //Analog voltage read




/*********************************************************************************************************
*                     Arduino Setup Statements
*
/********************************************************************************************************/
void setup(void) {
  Serial.begin(9600);
 

/**********************************************************************************************************
*                    Turn on Timer ISR
***********************************************************************************************************/
cli();//stop interrupts

//set timer0 interrupt at 2kHz
  TCCR0A = 0;// set entire TCCR2A register to 0
  TCCR0B = 0;// same for TCCR2B
  TCNT0  = 0;//initialize counter value to 0
  // set compare match register for 2khz increments
  OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)
  // turn on CTC mode
  TCCR0A |= (1 << WGM01);
  // Set CS11 and CS10 bits for 64 prescaler
  TCCR0B |= (1 << CS11) | (1 << CS10);   
  // enable timer compare interrupt
  TIMSK0 |= (1 << OCIE0A);

//set timer1 interrupt at 1Hz
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 1hz increments
  OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS12 and CS10 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10); 
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);

//set timer2 interrupt at 8kHz
  TCCR2A = 0;// set entire TCCR2A register to 0
  TCCR2B = 0;// same for TCCR2B
  TCNT2  = 0;//initialize counter value to 0
  // set compare match register for 8khz increments
  OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256)
  // turn on CTC mode
  TCCR2A |= (1 << WGM21);
  // Set CS11 bit for 8 prescaler
  TCCR2B |= (1 << CS11);   
  // enable timer compare interrupt
  TIMSK2 |= (1 << OCIE2A);


sei();//allow interrupts

// reset something?
  tft.reset();


  uint16_t identifier = tft.readID();


  tft.begin(identifier);


  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000


/*********************************************************************************************************
/                     Arduino Loop Statements
/*******************************************************************************************************/
void loop()
{
 
  digitalWrite(13, HIGH);// Get point on TFT board
  Point p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    Serial.print("\tPressure = "); Serial.println(p.z);

   
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
 
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
   //Setup Complete
   
   //Start Screen
   if (screen == 0){
     Isready = 0;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, RED);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(30, 25);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("START BULILDING");
   
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 0");
       screen  = 1;
       delay(100);
     }
     else{
       Serial.println("Not Red Button");
       
     }
  }
  else if (screen == 1){
     Isready = 1;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, GREEN);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(40, 30);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("  Ghost Block");
     
     tft.fillRect(20, 80, 200, 40, BLUE);
     tft.drawRect(20, 80, 200, 40, WHITE);
     tft.setCursor(40, 90);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println(" UnGhost Block");
     
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 1");
       screen  = 1;
       delay(100);
     }
     else if (((80 < p.y) && (p.y < 120 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 3");
       screen  = 0;
       delay(100);
     }
     else{
       Serial.println("Not green Button");
     }

     }// else if screen = 1
   
     
  }//If pressure is correct
 
}
//timer1 interrupt 1Hz
ISR(TIMER1_COMPA_vect){
      for(int quadrent = 0; quadrent < 4; quadrent++){
       for(int channel= 0; channel < 16; channel++){
         if (quadrent == 0){
            set_channel(channel); // turns on channel
            Serial.println(quadrent);
           
 
            int Analog_voltage = analogRead(A15);
           }
         else if (quadrent == 1){
           set_channel(channel); // turns on channel
           int Analog_voltage = analogRead(A14);
           Serial.println(quadrent);
           
           }
         else if (quadrent == 2){
           set_channel(channel); // turns on channel
           int Analog_voltage = analogRead(A13);
           Serial.println(quadrent);
           
           }
         else {
            set_channel(channel); // turns on channel
            int Analog_voltage = analogRead(A12);
            Serial.println(quadrent);
         
            delay(1000);
           }
     }//second for loop
    }// first for loop 
 }//Interrupt 
 
 

/*********************************************************************************************************
/                     Function Statements
/********************************************************************************************************/


Thanks for your time smiley
12  Using Arduino / Displays / 2.8" TFT touchscreen interrupts on: April 07, 2013, 05:25:31 pm
Is there a good way to use an interrupt on the TFT touchscreens? I have a for loop that takes up all the time so tht the controller cannot respond to the buttons on the screen. very troubling and could use some help

Thanks

Bill
13  Using Arduino / Displays / Denouncing a touchscreen button on: April 06, 2013, 11:39:58 pm
I have a 2.8" TFT LCD shield from ADAfruit industries and I've figured out how to create buttons at have them "Do stuff" but I am having a problem with Jitter in that all I am using so far is the delay(100); command to try and prevent any jitter. Sometimes it works and sometimes it does not. Any suggestions on how to improve this? The delays are highlighted below.

Thanks!

Code:
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    Serial.print("\tPressure = "); Serial.println(p.z);

   
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
 
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
   //Setup Complete
   
   //Start Screen
   if (screen == 0){
     Isready = 0;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, RED);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(30, 25);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("START BULILDING");
   
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 0");
       screen  = 1;
       
       delay(100);
     }
     else{
       Serial.println("Not Red Button");
       screen = 0;
     }
  }
  else if (screen == 1){
     Isready = 1;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, GREEN);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(40, 30);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("  Ghost Block");
     
     tft.fillRect(20, 80, 200, 40, BLUE);
     tft.drawRect(20, 80, 200, 40, WHITE);
     tft.setCursor(40, 90);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println(" UnGhost Block");
     
     Serial.println("running");
       
     }
   
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 1");
       screen  = 1;
       delay(100); // *****************// Here is the problem
     }
     else if (((80 < p.y) && (p.y < 120 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 3");
       screen  = 0;
       delay(100); // *****************// Here is the problem
     }
     else{
       Serial.println("Not green Button");
       screen = 1;
     }
  }
 
 if ((screen == 1) && (Isready == 1)){
    readAnalog_pin();
 }
14  Using Arduino / Project Guidance / COM-11102 Spark Fun Encoder Question on: March 04, 2013, 12:39:37 pm
Greetings,

I am building a hobby Coordinate Measuring Machine with four 1024 pulse rotary encoders from the spark fun website www.sparkfun.com item #11102. it is basically a four segment arm with no motor just encoders. I'm not really going into any reverse kinematics as my arm, hand and brain will be my feedback loop.

These devices output 1024 pulses per rotation. I will be using 4 of them. The regular arduino has a sampling rate of 15 khz do you think with hand motion (rpm max) that a regular Arduino UNO could keep up with these or do I need to use something like a DUE?

Also has anyone used that specific encoder before? Example code is always my best friend. Or has anyone ever attempted this?

Thanks !
15  Using Arduino / Displays / KS0108 on Duemoilanove on: September 23, 2012, 09:38:01 pm

Greetings I am having a great deal of trouble getting the KS0108 GLCD I purchased on Sparkfun about a year ago to work.
Here is the pinout for an standard Arduino Duemilanove (168/328).

The program below Which I have cut and pasted does not compile with the complaints listed below.
I have the ks0108.h installed in the libraries folder Which library should I use? I noticed there were several. THe LCD I have does not have any pin labels as well.

Any ideas?

Thanks

Code:
#include <ks0108.h>  // library header
#include <Arial14.h>  // font definition for 14 point Arial font.
#include "SystemFont5x7.h"   // system font
#include "ArduinoIcon.h"     // bitmap 
  unsigned long startMillis;
  unsigned int iter = 0;
void setup(){
  GLCD.Init(NON_INVERTED);   // initialise the library
  GLCD.ClearScreen(); 
  GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
  delay(3000);
  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7);       // select fixed width system font
}
void loop(){ // run over and over again
  startMillis = millis();
  while( millis() - startMillis < 1000){ // loop for one second
    GLCD.DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
    GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK);  // rounded rectangle around text area   
    for(int i=0; i < 62; i += 4)
      GLCD.DrawLine(1,1,63,i, BLACK);  // draw lines from upper left down right side of rectangle 
    GLCD.DrawCircle(32,31,30,BLACK);   // draw circle centered in the left side of screen 
    GLCD.FillRect(92,40,16,16, WHITE); // clear previous spinner position 
    GLCD.CursorTo(5,5);               // locate curser for printing text
    GLCD.PrintNumber(++iter);         // print current iteration at the current cursor position
  }
  // display number of iterations in one second
  GLCD.ClearScreen();               // clear the screen 
  GLCD.CursorTo(13,2);              // positon cursor 
  GLCD.Puts("FPS= ");               // print a text string 
  GLCD.PrintNumber(iter);           // print a number
 }



\libraries\ks0108\ks0108.cpp: In member function 'void ks0108::Init(boolean)':
\libraries\ks0108\ks0108.cpp:505: error: 'OUTPUT' was not declared in this scope
\libraries\ks0108\ks0108.cpp:505: error: 'pinMode' was not declared in this scope
\libraries\ks0108\ks0108.cpp:511: error: 'delay' was not declared in this scope


It does not appear to like this function "DrawBitmap as it is not highlighted in yellow as the rest are

 GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
Pages: [1] 2 3 ... 6