Zap'Em Blast'Em Robots
robots that play laser tag!
Loading...
Searching...
No Matches
photoresistor_task.c File Reference

Task logic for hit detection using photoresistors in game loop. More...

#include "photoresistor_task.h"
#include <stdio.h>

Functions

void photoresistor_task_run (PhotoresistorTask *photoresistor_task)
 Executes the current state of the photoresistor task.
void photoresistor_task_state_0_init (PhotoresistorTask *photoresistor_task)
 Initializes the photoresistor task (state 0).
void photoresistor_task_state_1_look (PhotoresistorTask *photoresistor_task)
 Checks for light detection and sets hit flag (state 1).
void photoresistor_task_state_2_hit (PhotoresistorTask *photoresistor_task)
 Waits for score handling and clears hit flag (state 2).

Detailed Description

Task logic for hit detection using photoresistors in game loop.

Author
Andrew Carr

Created on: Jun 3, 2025

Function Documentation

◆ photoresistor_task_run()

void photoresistor_task_run ( PhotoresistorTask * photoresistor_task)

Executes the current state of the photoresistor task.

Executes the current task state function.

Checks that the current state index is valid and invokes the corresponding state function. Traps in an infinite loop if state index is invalid.

Parameters
photoresistor_taskPointer to PhotoresistorTask structure.

◆ photoresistor_task_state_0_init()

void photoresistor_task_state_0_init ( PhotoresistorTask * photoresistor_task)

Initializes the photoresistor task (state 0).

Sets the next state to 1. Used to initialize any required sensor/button components.

Parameters
photoresistor_taskPointer to PhotoresistorTask structure.

◆ photoresistor_task_state_1_look()

void photoresistor_task_state_1_look ( PhotoresistorTask * photoresistor_task)

Checks for light detection and sets hit flag (state 1).

Checks for a light-based hit (state 1).

Transitions to the hit state if the difference between the current ADC value and zero calibration exceeds the threshold.

Parameters
photoresistor_taskPointer to PhotoresistorTask structure.

◆ photoresistor_task_state_2_hit()

void photoresistor_task_state_2_hit ( PhotoresistorTask * photoresistor_task)

Waits for score handling and clears hit flag (state 2).

Waits for hit flag to clear (state 2).

Transitions back to look state once the hit flag has been cleared externally (e.g., by the game task after scoring).

Parameters
photoresistor_taskPointer to PhotoresistorTask structure.