Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of ponglevering by
Diff: main.cpp
- Revision:
- 1:b179267654bb
- Parent:
- 0:31100e2cc464
--- a/main.cpp Tue Apr 10 10:34:51 2018 +0000
+++ b/main.cpp Tue Apr 17 12:26:28 2018 +0000
@@ -1,70 +1,197 @@
#include "mbed.h"
#include <iostream>
+#include <stdlib.h>
+#include <time.h>
+#include <stdio.h>
using namespace std;
-
-DigitalOut myled(LED1);
-DigitalOut b[5] = {p26, p27, p28, p29, p30}; // Bargraph
-DigitalOut c[4] = {p21, p22, p23, p24}; // bargraph sone
-Serial pc(USBTX, USBRX);
+InterruptIn button1(p5);
+InterruptIn button2(p6);
+InterruptIn slutt(p7);
-int main()
-{
- pc.printf("For spill 1 tast 1:\n\t");// Valg meny.
- pc.printf("For spill 2 tast 2:\n\t");
- pc.printf("For spill 3 tast 3:\n\t");
-
-
-
-
-
- while(1)
+DigitalOut myled(LED1);
+DigitalOut bargraph[5] = {p26, p27, p28, p29, p30}; // Bargraph
+DigitalOut bsone[4] = {p21, p22, p23, p24}; // bargraph sone
+DigitalOut led1(LED1), led2(LED2);
+BusOut buss(p26, p27, p28, p29, p30);
+int player1 = 0;
+int player2 = 0;
+
+Serial pc(USBTX, USBRX);
+
+ void flip1() { //her må vi prøve å få til at den bare kan trykkes inn på siste lys
+ cout << "value of player1: " << player1 << endl;
+ if (bsone[0].read() == 0)// && bargraph[0].read() == 1)
+ player1 = 1;
+ else {
+ led2 = 1;
+ exit(0);
+ }
+ }
+
+
+
+ void flip2() {
+ cout << "value of player2: " << player2 << endl; // //her må vi prøve å få til at den bare kan trykkes inn på siste lys
+ if (bsone[3].read() == 0)// && bargraph[5].read() == 1)
+ player2 = 1;
+ else {
+ led1 = 1;
+ exit(0);
+
+ }
+ }
+
+ void ut() {
+ cout << "Exit" << endl; //exit funksjon
+ bsone[0] = 0;
+ bsone[1] = 0;
+ bsone[2] = 0;
+ bsone[3] = 0;
+ buss = 15;
+ exit(0);
+ }
- {
- switch(pc.getc())// tall fra bruker blir til case
- {
- case '1':
+int main()
+{
+
+
+
+ pc.printf("Tast inn vansklighetsgrad 1 - 10:\n\t");// Valg meny.
+
+ //button1.fall(&flip1);
+ //button2.fall(&flip2);
+
+ float _wait; //vente funksjon
+ _wait = pc.getc() - 48;
+ if(_wait > 0 && _wait < 10)
+ {
+ //funksjon(_wait);
+ }
+ while(1)
+ {
+
+ button1.rise(&flip1); //intrykk fra bryter 1 som begynner funksjon flip 1
+ button2.rise(&flip2);//intrykk fra bryter 2 som begynner funksjon flip 2
+ slutt.rise(&ut); //exit funksjon
+
-
-
-
- for( int a = 5; a > -1; a = a-- ) {
- cout << "value of a1: " << a << endl;
- cout << "value of c1: " << c[1] << endl;
- cout << "value of c12: " << c[2] << endl;
- b[a] = 1;
- c[0] = 0;
- c[1] = 1;
-
- wait(0.5);
- b[a] = 0;
- }
- break;
-
- {
- case '2':
-
-
-
- for( int a = 5; a > -1; a = a-- ) {
- cout << "value of a2: " << a << endl;
- cout << "value of c2: " << c << endl;
- b[a] = 1;
- c[0] = 1;
- c[1] = 0;
-
- wait(0.5);
- b[a] = 0;
- }
- break;
- }
- }
+ //switch(pc.getc()) { // tall fra bruker blir til case
+ // case '1':
+ // while(1) {
+ for( int a = 4; a > -1; a = a - 1 ) { //lys bargraph 0-5 sone 0
+ // //////////////cout << "value of a1: " << a << endl;
+ bargraph[a] = 1;
+ bsone[0] = 0;
+ bsone[1] = 1;
+ bsone[2] = 1;
+ bsone[3] = 1;
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ for( int a = 4; a >= 0; a = a-- ) { //lys bargraph 0-5 sone 1
+ ////////////////cout << "value of a2: " << a << endl;
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 0;
+ bsone[2] = 1;
+ bsone[3] = 1;
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ for( int a = 4; a > -1; a = a - 1 ) { //lys bargraph 0-5 sone 2
+ //////////////////////////////////cout << "value of a1: " << a << endl;
+
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 1;
+ bsone[2] = 0;
+ bsone[3] = 1;
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ for( int a = 4; a > -1; a = a - 1 ) { //lys bargraph 0-5 sone 3
+ //////////////cout << "value of a2: " << a << endl;
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 1;
+ bsone[2] = 1;
+ bsone[3] = 0;
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ if(player2 != 1){ //sjekker om bryter 2 er 1 hvis ikke så bryter den
+ cout << "value of player2: " << player2 << endl;
+ pc.printf("GG p2 \n");
+ exit(0);
+ }
+
+ player2 = 0;
+
+ for( int a = 0; a < 5; a = a++ ) { //lys bargraph 4-0 sone 3
+ //////////////cout << "value of a3: " << a << endl;
+
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 1;
+ bsone[2] = 1;
+ bsone[3] = 0;
+
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ for( int a = 0; a < 5; a = a++ ) { //lys bargraph 0-4 sone 2
+ //////////////cout << "value of a4: " << a << endl;
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 1;
+ bsone[2] = 0;
+ bsone[3] = 1;
+
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+ for( int a = 0; a < 5; a = a++ ) { //lys bargraph 0-4 sone 1
+ //////////////cout << "value of a3: " << a << endl;
+
+ bargraph[a] = 1;
+ bsone[0] = 1;
+ bsone[1] = 0;
+ bsone[2] = 1;
+ bsone[3] = 1;
+
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+
+ for( int a = 0; a < 5; a = a++ ) { //lys bargraph 0-4 sone 0
+ //////////////cout << "value of a4: " << a << endl;
+ bargraph[a] = 1;
+ bsone[0] = 0;
+ bsone[1] = 1;
+ bsone[2] = 1;
+ bsone[3] = 1;
+
+ wait_ms(_wait*100);
+ bargraph[a] = 0;
+ }
+ if(player1 != 1){ //sjekker om bryter 1 er inne hvis ikke så exit
+ pc.printf("GG p1 \n");
+ cout << "value of player1: " << player1 << endl;
+ exit(0);
+ }
+ player1 = 0;
}
-
-
-}
+}
+
+
\ No newline at end of file
