Last state if statements with hall effect sensor

Ok i must add that i am new to this. You know how when you use code like this
so when you click a momentary switch button the led stays on and when you click it again it turns off right? I want to find a way to implement it with a hall effect sensor but im having trouble.

/* sketch 3 
turn on a LED when the button is pressed and let it on 
until the button is pressed again
*/
int pinButton = 8;
int LED = 2;
int stateLED = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 200;
 
void setup() {
  pinMode(pinButton, INPUT);
  pinMode(LED, OUTPUT);
}
 
void loop() {
  stateButton = digitalRead(pinButton);  
  if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
    if(stateLED == HIGH){
      stateLED = LOW; 
    } else {
       stateLED = HIGH; 
    }
    time = millis();
  }
  digitalWrite(LED, stateLED);
  previous == stateButton;
}

This is the code i have right now basically when my tx attiny85's hall effect detects magnetic waves it knows to send manchester code to rx and when it receives the data an led turns on. heres my problem i want it to stay on without the magnet present and turn off when place the magnet in front of the sensor.
heres my code.

#include <Manchester.h>

  #define TX_PIN 0 //pin where your transmitter is connected
  const int hallPin = 4;
  int hallState = 0;
  uint16_t transmit_data = 2761;
  uint16_t transmit_t = 2000;
  uint16_t transmit_y = 4000;
  uint16_t transmit_g = 5000;
 
  void setup() {
    
  man.setupTransmit(TX_PIN, MAN_1200);
  pinMode(hallPin, INPUT);
  Serial.begin(9600);
} 
  void loop() {
    hallState = digitalRead(hallPin);
    if (hallState == LOW) 
    {
  man.transmit(transmit_data);
  man.transmit(transmit_t);  
    } else {
      man.transmit(transmit_y);
      man.transmit(transmit_g);
      }
    }

Thank you guys for taking the time to read the post. =]

That code should work but will send codes continuously. If you only want to send a code when the hallState changes you could do something like

void loop() {
    hallState = digitalRead(hallPin);
    if (hallState != prev_hallState) {
    
    // your existing code here

    prev_hallState=hallState;
    }

rw950431:
That code should work but will send codes continuously. If you only want to send a code when the hallState changes you could do something like

void loop() {

hallState = digitalRead(hallPin);
    if (hallState != prev_hallState) {
   
    // your existing code here

prev_hallState=hallState;
    }




Wow that's cool, it'll prob save power which is awesome. However when I move the magnet away it will then send the other data which will turn off the led and its not what I want. I would like the led to stay on if I move the magnet away and turn off when I bring the magnet back then remove the magnet and it stays off and then comes back on when I bring it back and so on etc.
Any ideas on how I could do that code wise?
Thanks again for the help

All my code does is provide a means of detecting when the hall state changes- it will get triggered when magnet comes and also magnet goes. Within that IF block you just need separate sections for if (hallState==HIGH) and if (hallState==LOW) to take whatever action is needed in either case. If you just want to toggle an output each time the hall state changes then you dont need any IF's just the statement digitalWrite(LED_pin, !digitalRead(LED_pin))

If you are seeking low power consumption then you need to learn about hardware interrupts see Arduino Playground - Interrupts as a starting point