Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int bitbut1 = 2;
- int bitbut2 = 3;
- int bitbut3 = 4;
- int led1 = 5; //Forteller hvilken enhet som er på hvilken port
- int led2 = 6;
- int led3 = 7;
- int led4 = 8;
- int led5 = 9;
- int led6 = 10;
- int led7 = 11;
- int but1 = 12;
- int nummer;
- int a;
- int b;
- int c;
- void setup() {
- pinMode(led1, OUTPUT); //Definerer LED-pins som outputs
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- pinMode(led4, OUTPUT);
- pinMode(led5, OUTPUT);
- pinMode(led6, OUTPUT);
- pinMode(led7, OUTPUT);
- pinMode(but1, INPUT_PULLUP);
- pinMode(bitbut1, INPUT_PULLUP);
- pinMode(bitbut2, INPUT_PULLUP);
- pinMode(bitbut3, INPUT_PULLUP);
- }
- void loop() {
- if(digitalRead(but1) == LOW) //Sjekk om knappen er trykket inn
- {
- a = digitalRead(bitbut1);
- b = digitalRead(bitbut2);
- c = digitalRead(bitbut3);
- nummer = (a*1)+(b*2)+(c*4);
- //loops();
- if (nummer == 7){
- terning7(); }
- if (nummer == 6){
- terning6(); }
- if (nummer == 5){
- terning5(); }
- if (nummer == 4){
- terning4(); }
- if (nummer == 3){
- terning3(); }
- if (nummer == 2){
- terning2(); }
- if (nummer == 1){
- terning1(); }
- }
- }
- void alloff() {
- delay(1000);
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- digitalWrite(led6, LOW);
- digitalWrite(led7, LOW);
- }
- void terning1() {
- digitalWrite(led4, HIGH);
- delay(250);
- alloff();
- }
- void terning2() {
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- delay(250);
- alloff();
- }
- void terning3() {
- digitalWrite(led1, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led7, HIGH);
- delay(250);
- alloff();
- }
- void terning4(){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led6, HIGH);
- digitalWrite(led7, HIGH);
- delay(250);
- alloff();
- }
- void terning5() {
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led6, HIGH);
- digitalWrite(led7, HIGH);
- digitalWrite(led4, HIGH);
- delay(250);
- alloff();
- }
- void terning6() {
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, HIGH);
- digitalWrite(led7, HIGH);
- delay(250);
- alloff();
- }
- void terning7() {
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, HIGH);
- digitalWrite(led7, HIGH);
- delay(250);
- alloff();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement