Although consciousness has been difficult to define, most researchers in artificial intelligence would agree that AI systems to date have not exhibited anything resembling consciousness. But is a conscious machine possible in the near future? I suggest that a new definition of consciousness may provide a basis for developing a conscious machine. The key is pattern recognition of correlated events in time, leading to the identification of a unified self-agent. Such a conscious system can create a simplified virtual environment, revise it to reflect updated sensor inputs, and partition the environment into self, other agents, and relevant objects. It can track recent time sequences of events, predict future events based on models and patterns in memory, and attribute causality to events and agents. It can make rapid decisions based on incomplete data, and can dynamically learn new responses based on appropriate measures of success and failure. The central aspect of consciousness is the generation of a dynamic narrative, a real-time model of a self-agent pursuing goals in a virtual reality. A conscious machine of this type may be implemented using an appropriate neural network linked to episodic memories. Near-term applications may include autonomous vehicles and online agents for cybersecurity. Paper presented at virtual IEEE International Conference on Rebooting Computing (ICRC), Nov. 2021. To be published in conference proceedings 2022.