char vuMeter[] = {0, 1, 3, 7, 15, 31, 63, 127};
int tipka = 7;
int ledModra = 11;
void setup() {
DDRD = 0x7F;
DDRB |= 0x08; // 11
PORTD|= 0x80;
}
void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 7);
int izpis = vuMeter[pot];
bool tipkaStanje = PIND & 0x80;
if(tipkaStanje == LOW) PORTB |= 0x08;
else PORTB = 0x00 & 0xF7;
PORTD = izpis | 0x80; // pin za tipko mora biti ves čas v 1
delay(300);
}
/* ************************** A - registri**********************
char vuMeter[] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
void setup() {
DDRD = 0xFF;
}
void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 8);
PORTD = vuMeter[pot];
delay(300);
*************************** A - pinMode ************************
char vuMeter[] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
void setup() {
for(int x = 0; x < 8; x ++) pinMode(x, OUTPUT);
}
void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 8);
int izpis = vuMeter[pot];
for(int i = 0; i < 8; i++){
int k = izpis & 0x01;
digitalWrite(i, k);
izpis >>= 1;
}
delay(300);
}
************************* B - pinMode *************************
char vuMeter[] = {0, 1, 3, 7, 15, 31, 63, 127};
int tipka = 7;
int ledModra = 11;
void setup() {
for(int x = 0; x < 7; x ++) pinMode(x, OUTPUT);
pinMode(tipka, INPUT_PULLUP);
}
void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 7);
int izpis = vuMeter[pot];
if(digitalRead(tipka) == LOW) digitalWrite(ledModra, HIGH);
else digitalWrite(ledModra, LOW);
for(int i = 0; i < 7; i++){
int k = izpis & 0x01;
digitalWrite(i, k);
izpis >>= 1;
}
delay(300);
}
********************* B - registri **************************
char vuMeter[] = {0, 1, 3, 7, 15, 31, 63, 127};
int tipka = 7;
int ledModra = 11;
void setup() {
DDRD = 0x7F;
DDRB |= 0x08; // 11
PORTD|= 0x80;
}
void loop() {
int pot = analogRead(A0);
pot = map(pot, 0, 1023, 0, 7);
int izpis = vuMeter[pot];
bool tipkaStanje = PIND & 0x80;
if(tipkaStanje == LOW) PORTB |= 0x08;
else PORTB = 0x00 & 0xF7;
PORTD = izpis | 0x80; // pin za tipko mora biti ves čas v 1
delay(300);
}
*****************************************************************/