I made this simple code to give me a visual feedback of air quality inside my workplace, and I want to use an ATtiny13a, but the LEDs simply light up and don't change as they're supposed to. I don't think it's a core issue because I've tried on two different versions of the micro core and I also tested on the ATtiny85. It only works on the arduino mega.
I have no idea what might be.
int HarmfulGases = 0;
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
HarmfulGases = analogRead(A2);
if ( HarmfulGases <= 70 ) {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 70 && HarmfulGases <= 120 ) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 120 && HarmfulGases <= 200 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 200 && HarmfulGases <= 280 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
}
else if ( HarmfulGases > 280 && HarmfulGases <= 350 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW) ;
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}
else if ( HarmfulGases > 350 ) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}
}
pylon
December 7, 2016, 2:00pm
2
Which board package do you use? Please provide a link to it. My guess is that A2 isn't correctly configured.
pylon
December 7, 2016, 6:04pm
4
Which core do you use for the ATtiny 85? Do you use the default core_settings.h?
HarmfulGases = analogRead(A2);
For the core you are using, which pin is A2?
Do you have your sensor connected to the correct pin?
It's physical pin number 3. Yes, I am using the right pin according to the datasheet... Is there a way to use the real AVR names? I've done that with digital pins like "pcint" but it doesn't work when I put ADC2 for example.
Try 2 instead of A2. Maybe A2 is not correctly defined.
Whaaaat hahaahah, it's working!!!!!!! Thank you VEEERRRY much! I just changed A2 to 2.
int HarmfulGases = 0;
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
HarmfulGases = analogRead(2);
if ( HarmfulGases <= 70 ) {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 70 && HarmfulGases <= 120 ) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 120 && HarmfulGases <= 200 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
}
else if ( HarmfulGases > 200 && HarmfulGases <= 280 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
}
else if ( HarmfulGases > 280 && HarmfulGases <= 350 ) {
digitalWrite(0, LOW);
digitalWrite(1, LOW) ;
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}
else if ( HarmfulGases > 350 ) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}
}
You are welcome. Glad to know it is working.