Hi, wonder if any one can help. Having need to use as small a mcu., as I can in a model rail sketch I chose to use an Attiny85. the trouble is I cannot get the somewhat simple program to work. I have been wondering whether it would be better if I specified the pinouts using 'C'., but I am not sure of my 'C' syntax, vis PORTB = 1; DDRB = 0b00011010; nor do I know how to read analog, etc.
For pins, I am using:
Pin ide location Use
1 reset Rst
2 3 Out
3 4 Out
4 Gnd Grd
5 0 In
6 1 Out
7 A1 in my case. In
8 Vcc ditto 3.6V . Vcc
/******* Multiple Unit H&T Lighting **********
Title: DMU_Lite
Author: HCS Date: 08/01/2016. Amended. 17/01/2016
Runs off engine DC., power circuit to accommodate
DCC., running also.
Microcontroller = Attiny85 or 13A.*/
#include <stdio.h>
boolean flag[2] = {1, 2}; // flags for randome use
boolean frLights = 3; // front lights high on PIN 2 PB1
boolean bkLights = 4; // rear lights high on PIN 3 PB0
boolean dirn = 0; // sets motor dirnection as forward on Pin 5. 0 = backwards.
int battery = A1; // Charge battery pin used to find charge level Pin 7.
long charge = 1; // charge, PB2 supply current to battery if necessary. Pin 6
void setup() {
pinMode(frLights, OUTPUT);
pinMode(bkLights, OUTPUT);
pinMode(battery, INPUT);
pinMode(charge , OUTPUT);
pinMode(dirn, INPUT); // Loco dirnection. Pin 5
digitalWrite(frLights, HIGH);// Switch on front lights Pin 2
digitalWrite(bkLights, HIGH); // Switch off rear lights Pin 3
digitalWrite(charge , HIGH); // Charge battery necessity. Pin 6
// Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
/********* Determin dirnection ********/
boolean dir = digitalRead(dirn);
if (dir = HIGH) { // Battery dir'n on pin 5 Attiny85
flag[1] = HIGH;
flag[2] = LOW;
digitalWrite(frLights, HIGH); // pin 2
digitalWrite(bkLights, LOW); // pin 3
}
else {
digitalWrite(frLights, LOW);
digitalWrite(bkLights, HIGH);
flag[2] = HIGH;
flag[1] = LOW;
}
/******** Battery State *********/
long val = analogRead(battery);
if (val <= 3) {
digitalWrite(charge, HIGH);
}
else if (val > 3.6) {
digitalWrite(charge, LOW);
}
else {
digitalWrite(charge, LOW);
}
}
I have also included a sketch of my schema. The cores are those of MR., D.A.Mellis Ver., 1.1.0
Hope you can help.