/**************************************************************************
Blink 1.0
ci sono due led ed un pulsante
- un led lampeggia con una frequenza ed un duty cicle impostato mediante il timer
- un pulsante chiama una funzione di interrupt hw per switchare da un led all'altro
Cosa c'è di speciale?
Nel loop non ci sono istruzioni
This program was written in the simplest possible way in order to prevent
a not excellent knowledge of programming language. It is possible use it
HOW IT IS only on the wokwi simulator
For no reason the publication of this code
it makes the authors responsible and even less obliges them to
provide support and / or any explanation or clarification
However, if possible, we will try to answer
to any questions, without any obligation and / or commitment and / or
responsibility
.................................................. .......
These phrases will always reported in complete form included this following
This software can be used for any purpose under own total, complete and
exclusive responsibility.
Anyone can modify it and adapt it to own
needs, always reporting the present in its entirety
phrases, even after importnt changes.
by https://www.facebook.com/groups/883620498953478
Thank you
Questo programma è stato scritto nel modo più semplice possibile al fine
di prevenire una non ottima conoscenza del linguaggio di programmazione.
È possibile utilizzarlo COSI' COME È solo sul simulatore wokwi
Per nessun motivo la pubblicazione di questo codice rende gli autori
responsabili e ancor meno li obbliga a fornire supporto e/o qualsiasi
spiegazione o chiarimento.
Tuttavia, se possibile, cercheremo di rispondere a qualsiasi domanda,
senza alcun obbligo e/o impegno e/o responsabilità
.................................................. .......
Queste frasi saranno sempre riportate in forma completa inclusa la seguente
Questo software può essere utilizzato per qualsiasi scopo in proprio
totale, completa ed esclusiva responsabilità.
Chiunque può modificarlo e adattarlo alle proprie esigenze, riportando
sempre il presente testo nella sua interezza, anche a vale di importanti
modifiche.
by https://www.facebook.com/groups/883620498953478 "
Thank you
**************************************************************************/
#define led1 2 // led 1 sulla porta 2
#define led2 4 // led 2 sulla porta 4
#define button 3 // pulsante sulla porta 3
volatile bool buttonState;
volatile bool state=false;
int led=2;
void swap() {
buttonState=!buttonState;
PORTD &= B11101011;
if (buttonState ) led=led1;
else led=led2;
}
ISR(TIMER1_COMPA_vect) {
state =!state;
digitalWrite(led,state);
}
void setup() {
cli();
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(button,INPUT_PULLUP);
TCCR1A = 0;
TCCR1B = 0;
TCCR1B |= (1 << CS11)|(1 << CS10);
TCCR1B |= (1 << WGM12);
OCR1A = 100000;
TIMSK1 |= (1 << OCIE1A);
sei();
attachInterrupt(digitalPinToInterrupt(button),swap,FALLING);
PORTD &= B11101011;
buttonState=1;
}
void loop() {
}