PDA

View Full Version : How to use Xcode output signal to control LED light?




Toptwo
May 10, 2012, 10:43 AM
if i want to write a program to output signal to control relay or led.
how to write that?
did any reference books to recommend?

http://www.youtube.com/watch?v=PSKyUhKlVPo



ytk
May 10, 2012, 01:23 PM
You'd need some sort of hardware interface. If you just want to generate a high/low signal, you can simply use a USB to serial adaptor, and set the DTR and RTS lines as needed. You could also read signals over the CD, DSR, CTS, and RI lines. This would give you 2 lines out and 4 in. I'm not sure how exactly to address the serial port in ObjC/Cocoa, but I'm certain there's a way, either via the built-in serial library or some third party library.

If you're looking to do something more complicated, or require more control lines, you might want to look into using an Arduino or similar microcontroller as your hardware interface. You could hook up your input/output lines (the Arduino Uno gives you a total of 20 I/O lines (although only 18 if you're controlling it via your computer) and if you need more you can always multiplex them via a shift register. You can either write your code directly to run on the Arduino, or set it up so it accepts commands from the computer to turn the pins on and off.

firewood
May 10, 2012, 05:02 PM
You can't use Xcode alone. You probably also need some extra hardware to talk to from the Mac (either USB, networked micro, or a PCI card). Then you need to find and read the reference for that particular item of external hardware to determine what API it requires to send it commands. Then you may also need to write code on some IDE other than Xcode to program that external hardware (if it's an arduino, beagleboard or rasberry pi, for instance).

chown33
May 10, 2012, 09:05 PM
Here's an article about not using Xcode:
http://www.evilmadscientist.com/article.php/avrblink

It relies on CrossPack (AVR cross-compiler tools), Terminal.app, and make.

Toptwo
May 11, 2012, 01:28 AM
thanks for reply:D
i'll try.