i posted code that works on an arduino. just change the pin appropriately
doubt multi-tasking is necessary