Programma voor de Attiny 85 heb ik hier gepost:
// Train crossing with leds, sound and motor for ATTINY45/85
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 0; // PIN 5 the 2 blinking LED pins
const int ledPin2 = 1; // PIN 6 of this
const int ledPin3 = 2; // PIN 7 used for relais motor
const int inPin = 3; // PIN 2 Input reedcontact of train to start
const int soUnd = 4; // PIN 3 Buzzer
// Variables will change:
int crossing_on = 0; // Complete sequence on-off
int blinkCount = 0; // counting time fulfilled
int ledState1 = LOW; // ledState used to set the LED
long previousMillis1 = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval1 = 53; // time interval to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(inPin, INPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// Wait for input signal to start sequence
if(crossing_on==0) { //sequence nog niet running? dan act
int buttonstate = digitalRead(inPin);
if (buttonstate==HIGH) { //standard reedswitch start sequence on PIN 7
crossing_on = 1;
blinkCount=0;
}
else {
crossing_on = 0;
}
}
// TASK 1 Blinking the LEDS of Signal(s)
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
if(crossing_on==1) {
unsigned long currentMillis1 = millis();
if(currentMillis1 - previousMillis1 > interval1) {
// save the last time you blinked the LED
previousMillis1 = currentMillis1;
// if the LED is off turn it on and vice-versa:
blinkCount++;
// check if some time is passed to do some additional action
if(blinkCount == 1) {
digitalWrite(ledPin3, HIGH); // turn on relais to close gate
}
if(blinkCount == 7) {
digitalWrite(ledPin3, LOW); // turn relais off
}
if(blinkCount == 25) {
digitalWrite(ledPin3, HIGH); // turn on relais second time (open gate)
}
if(blinkCount == 32) {
digitalWrite(ledPin3, LOW); //turn off relais again
}
if(blinkCount == 45) {
digitalWrite(ledPin, LOW); //sequence klaar alles weer resetten
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
crossing_on = 0; // en sequence klaarzetten voor volgende ronde
}
/// blinking LEDS
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
// set the LED with the ledState of the variable:
if(crossing_on == 1) {
if (ledState1 == LOW)
{digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
tone(soUnd,2355,3); // basis 2365
}
else
{digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, LOW);
tone(soUnd,2355,3);
}
}
}
}
}
En voor de nabouwer hier de aansluitingen van de Attiny85 (of attiny45):
PIN 4 & 8 : voeding + ground
PIN 5 & 6 : rode leds in andreaskruizen; die gaan afwissellend knipperen.
PIN 7 : uitgang naar Relais via ULN2803. hiermee wordt de motor van de Falleroverweg getriggerd.
PIN 3 : Buzzer
PIN 2 : ingang voor railsensor
PIN 1 : Reset. Wordt verder niet gebruikt en hoeft niet aagesloten te worden.