Page 1 of 1

Few questions

Posted: Sun Oct 26, 2003 2:20 am
by Rogelio
Hi

I'm new to qbasic, and I barely know how to program in c.

Using the printer's port I've connected it to a breadbord(?) and it has 8 leds. I tested it and it works.

How do I assing each led to a letter on my keyboard?
How do I program it so when I press a letter its corresponding led turns on, and if I press it again it turns off? Using qbasic of course.

I know I need to put the printer's port address in a variable, but I don't know about the rest.

Could someone be kind enough to point me in the right direction?

Thanks in advance!

Re: Few questions

Posted: Mon Oct 27, 2003 3:23 pm
by frankiebaby
Hey there! I wrote an entire program based on this purpose and built a box with solid state relays to control light strings and spots. i can send you a snippit of my source. So, since you tested it, you figuered out how to tell the printer port to turn led's on? sending a number from 0 to 255 to the port. well, do you understand how binary works? each of the eight bits stands for a light:

0 0 0 0 0 0 0 0

so to turn on the first, second and fourth light:

0 0 0 0 1 0 1 1

which coresponds to 1 + 2 + 8 = 11, so sending an eleven will do this.

i must go now, i will send you source later today

Re: Few questions

Posted: Tue Oct 28, 2003 12:06 am
by Rogelio
Thank you very much, that source will be very helpful.
And yes I knew about the binary numbers, but I hadn't look it at that way. But I don't know how to implement it cause each light is independent form each other.

Thank you very much.  :D

Re: Few questions

Posted: Tue Oct 28, 2003 3:10 pm
by frankiebaby
here is the "core" that i used to control hardware

Code: Select all

DEFINT A-Z
DIM GRID(1 TO 128) AS INTEGER


DO
KEY$ = INKEY$
SELECT CASE KEY$
 CASE "1"
  IF GRID(1) THEN GRID(1) = 0 ELSE GRID(1) = 1
 CASE "2"
  IF GRID(2) THEN GRID(2) = 0 ELSE GRID(2) = 1
 CASE "3"
  IF GRID(4) THEN GRID(4) = 0 ELSE GRID(4) = 1
 CASE "4"
  IF GRID(8) THEN GRID(8) = 0 ELSE GRID(8) = 1
 CASE "5"
  IF GRID(16) THEN GRID(16) = 0 ELSE GRID(16) = 1
 CASE "6"
  IF GRID(32) THEN GRID(32) = 0 ELSE GRID(32) = 1
 CASE "7"
  IF GRID(64) THEN GRID(64) = 0 ELSE GRID(64) = 1
 CASE "8"
  IF GRID(1) THEN GRID(128) = 0 ELSE GRID(128) = 1
END SELECT

FOR X = 1 TO 128
 BIT = BIT + (GRID(X) * X)
NEXT

OUT 888, BIT
LOOP

i know this is a sumwhat wasteful way to do this (i wrote this a year and a half ago) but it works great for the program i wrote