Skip to content

Instantly share code, notes, and snippets.

@dwhacks
Last active December 4, 2020 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dwhacks/8108691 to your computer and use it in GitHub Desktop.
Save dwhacks/8108691 to your computer and use it in GitHub Desktop.
attiny85 Mailbox TX
#include <Manchester.h>
/*
You've Got Snail Mail by dwhacks: http://daynewaterlow.com
Using Arduino-Tiny core on the Attiny85
http://code.google.com/p/arduino-tiny/
Notifier Code borrowed from: https://github.com/LowPowerLab/MailboxNotifier
Manchester library for Arduino from: http://mchr3k.github.io/arduino-libs-manchester/
*/
#define TX_PIN 3 //pin where your transmitter is connected
#define LED_PIN 0 //pin for blinking LED
#define HALLSENSOR 2 // pin to read hall sensor
#define HALLSENSOR_EN 1 // turn this pin HIGH to power the hall sensor
long doorPulseCount = 0; // opened then closed counter
uint8_t moo = 1; //last led status
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(HALLSENSOR, INPUT);
pinMode(HALLSENSOR_EN, OUTPUT);
digitalWrite(LED_PIN, moo);
man.workAround1MhzTinyCore(); //add this in order for transmitter to work with 1Mhz Attiny85/84
man.setupTransmit(TX_PIN, MAN_1200);
}
void loop() {
byte reading = hallSensorReading(); // check the hall sensor
if (reading == 1){
if (++doorPulseCount == 1)
{
man.transmit(1);
//moo = ++moo % 2;
digitalWrite(LED_PIN, HIGH);
delay(50);
digitalWrite(LED_PIN, LOW);
}
}
else if (doorPulseCount >=1)
{
doorPulseCount = 0; //reset counter
}
}
byte hallSensorReading()
{
digitalWrite(HALLSENSOR_EN, HIGH); //turn sensor ON
delay(1); //wait a little
byte reading = digitalRead(HALLSENSOR);
digitalWrite(HALLSENSOR_EN, LOW); //turn sensor OFF
return reading;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment