Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Please help me with "int function()" ! [Solved]  (Read 249 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, first of all sorry if i posted this in a wrong section, this is my first post.

Anyway... I am not very experienced with making "int functions()" (the ones outside the main loop)

I'm trying to make a "getKeyboard" function to read the PS/2 keyboard buttons, the code works in the main loop, but when i try to put it into its own function (to make things a lot more organized), it gives me this error message :

Code:
lcd_Keyboard_Test.cpp: In function 'void loop()':
Lcd_Keyboard_Test:151: error: invalid conversion from 'int (*)()' to 'int'

Here is my code :

Code:
/*  PS2Keyboard library example
  
  PS2Keyboard now requries both pins specified for begin()

  keyboard.begin(data_pin, irq_pin);
  
  Valid irq pins:
     Arduino:      2, 3
     Arduino Mega: 2, 3, 18, 19, 20, 21
     Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
     Teensy 2.0:   5, 6, 7, 8
     Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
     Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
     Sanguino:     2, 10, 11
  
  for more information you can read the original wiki in arduino.cc
  at http://www.arduino.cc/playground/Main/PS2Keyboard
  or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
  
  Like the Original library and example this is under LGPL license.
  
  Modified by Cuninganreset@gmail.com on 2010-03-22
  Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
  
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);    
  
#include <PS2Keyboard.h>

const int DataPin = 20;
const int IRQpin =  21;

int key_in = 0;

int input = 0;
int val = 100;

   byte one[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111
};
   byte two[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111
};
   byte three[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111
 };
   byte four[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
   byte five[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
   byte six[8] = {
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
   byte seven[8] = {
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
   byte eight[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

PS2Keyboard keyboard;

void setup() {
  
  lcd.begin(16,2);
  
  lcd.createChar(1, one); //send the custom characters to the LCD
  lcd.createChar(2, two); //             ||
  lcd.createChar(3, three);//            ||
  lcd.createChar(4, four);//             ||
  lcd.createChar(5, five);//             ||
  lcd.createChar(6, six);//              ||
  lcd.createChar(7, seven);//            ||
  lcd.createChar(8, eight);//            \/          
  lcd.setCursor(0,0);
  lcd.print ("      LCD      ");  
  lcd.setCursor(0,1) ;
  lcd.print ("   BAR GRAPH   ");  
  delay(1000);
  lcd.clear();
  
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  Serial.println("Keyboard Test:");
  
  pinMode(10,OUTPUT);
  
}

void loop() {
  
   input = getKeyboard;
  
   val = val + input;
    
   setVal(val);
   printVal(val);
   barGraph(val);
  
}

int getKeyboard()
{
if (keyboard.available()) {
    
     Serial.println("////keyboard available\\\\");
    
   char c = keyboard.read();
    
     if (c == PS2_UPARROW) {
       if(val<100){
     // val++;
     return 1;
      Serial.println("UP arrow pressed");
       }
    }
    else if (c == PS2_DOWNARROW) {
      if(val>0){
    // val--;
    return -1;
     Serial.println("DOWN arrow pressed");
      }
   }  
  
 }
}


void setVal(int val) {
  
  val = map(val, 0, 100, 0, 255);
  
  analogWrite(10, val);
  
}

void printVal(int val) {
  
   if(val<10){
lcd.setCursor(2, 0);
lcd.print(val);
lcd.setCursor(0, 0);
lcd.print("  ");
lcd.setCursor(3, 0);
lcd.print("%");
}
if(val>=10 && val < 100){
lcd.setCursor(1, 0);
lcd.print(val);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(3, 0);
lcd.print("%");
}
if(val>=100){
lcd.setCursor(0, 0);
lcd.print(val);
lcd.setCursor(3, 0);
lcd.print("%");
}
  
  
}  

void barGraph(int val) {
  
  val = map(val, 0, 100, 0, 16);
  
        if(val != 0){
    if(val <= 8){
    lcd.setCursor(15,1);  
    lcd.write(val);  //print out data
    lcd.setCursor(15,0);  
    lcd.print(" ");  //clear out remainder data
    }
      }
    if(val == 0){
      lcd.setCursor(150,1);  
    lcd.print(" ");  //print out data
    lcd.setCursor(15,0);  
    lcd.print(" ");  //clear out remainder data
    }
    
      
    if(val > 8){
    lcd.setCursor(15,1);  
    lcd.write(8);  //print out full block
    lcd.setCursor(15,0);  
    lcd.write(val-8);  //print out remainder data
    }
    
}    

/*

if (c == PS2_ENTER) {
      Serial.println();
    } else if (c == PS2_TAB) {
      Serial.print("     ");
    } else if (c == PS2_ESC) {
      Serial.print("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      Serial.print("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      Serial.print("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      Serial.print("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      Serial.print("[Right]");
    } else if (c == PS2_UPARROW) {
      Serial.print("[Up]");
    } else if (c == PS2_DOWNARROW) {
      Serial.print("[Down]");
    } else if (c == PS2_DELETE) {
      Serial.print("[Del]");
      
*/


Here is the part that doesn't work :

Code:
void loop() {
  
   input = getKeyboard;
  
   val = val + input;
    
   setVal(val);
   printVal(val);
   barGraph(val);
  
}

int getKeyboard()
{
if (keyboard.available()) {
    
     Serial.println("////keyboard available\\\\");
    
   char c = keyboard.read();
    
     if (c == PS2_UPARROW) {
       if(val<100){
     // val++;
     return 1;
      Serial.println("UP arrow pressed");
       }
    }
    else if (c == PS2_DOWNARROW) {
      if(val>0){
    // val--;
    return -1;
     Serial.println("DOWN arrow pressed");
      }
   }  
  
 }
}
« Last Edit: February 12, 2013, 06:53:34 pm by vacer25 » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 989
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
   input = getKeyboard;

You probably meant to call the function:

Code:
   input = getKeyboard();

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much I should of thought of that before !
Logged

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: