Dangerous Prototypes

Other projects => Past projects => #twatch network LCD backpack => Topic started by: mcdanne82 on January 31, 2010, 01:55:56 pm

Title: How can I connect buttons?
Post by: mcdanne82 on January 31, 2010, 01:55:56 pm
Hi
I am new to C, only worked in basic before.

It would be realy nice to add some buttons to the LCD and to read the status of them from PC software.
But there is not any free pins that is easy to connect to so i would like to start to connect the PGD and PGC to two buttons.

Code: [Select]
TRISB=0xC0; 
if  (PORTBbits.RB6=1) {
TCPPutROMString(MySocket, (ROM BYTE*) "S1:ON");
TCPFlush(MySocket);
}else{
TCPPutROMString(MySocket, (ROM BYTE*) "S1:OFF");
TCPFlush(MySocket);
}
if  (PORTBbits.RB7=1) {
TCPPutROMString(MySocket, (ROM BYTE*) "S2:ON");
TCPFlush(MySocket);
}else{
TCPPutROMString(MySocket, (ROM BYTE*) "S2:OFF");
TCPFlush(MySocket);
}

But I must have done somthing wrong while I only get S1:ON in respons when it is grounded and when it is connected to 3,3v
Title: Re: How can I connect buttons?
Post by: ian on January 31, 2010, 02:14:12 pm
PORTBbits.RB6=1

This is always true in C. A single = tells the port pin to be set/clear, which it does, so it is true. You want a double ==, which tests if the pin is equal to the value 1.

PORTBbits.RB6==1

Try that, it should work.

Please share your setup and results when you're done, I'm sure other people would be interested too.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.00882055320session_write_close ( )...(null):0
20.00912186912ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.00912187688Database_MySQL->query( ).../DatabaseHandler.php:119
40.05412326416Database_MySQL->error( ).../Db-mysql.class.php:273