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 mbed_pong22 by
main.cpp
- Committer:
- Adrianmo
- Date:
- 2018-04-17
- Revision:
- 1:b179267654bb
- Parent:
- 0:31100e2cc464
File content as of revision 1:b179267654bb:
#include "mbed.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
using namespace std;
InterruptIn button1(p5);
InterruptIn button2(p6);
InterruptIn slutt(p7);
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);
}
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
//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;
}
}
