Help needed to convert some code.

That's the PC end of your program - you need to read about how to write sketches for the Arduino.

There are tutorials and examples over at the main Arduino site.