What have you tried? Post your best attempt at the code. Please format your code before posting in a code block.
Tell us what the code actually does and how that differs from what you want.
Please post a schematic. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
Or How to make a schematic to post.