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. =]