-
-
Save YutaSeya/5757f699669601cf3afb989dd8040170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <unistd.h> | |
#include <iostream> | |
using namespace std; | |
bool get0() | |
{ | |
bool sw_data = false; | |
FILE *sw; | |
sw = fopen("/dev/rtswitch0", "r"); | |
char data = fgetc(sw); | |
if ( data == '0' ){ | |
sw_data = true; | |
} else { | |
sw_data = false; | |
} | |
fclose(sw); | |
return sw_data; | |
} | |
bool get1() | |
{ | |
bool sw_data = false; | |
FILE *sw; | |
sw = fopen("/dev/rtswitch1", "r"); | |
char data = fgetc(sw); | |
if ( data == '0' ){ | |
sw_data = true; | |
} else { | |
sw_data = false; | |
} | |
fclose(sw); | |
return sw_data; | |
} | |
bool get2() | |
{ | |
bool sw_data = false; | |
FILE *sw; | |
sw = fopen("/dev/rtswitch2", "r"); | |
char data = fgetc(sw); | |
if ( data == '0' ){ | |
sw_data = true; | |
} else { | |
sw_data = false; | |
} | |
fclose(sw); | |
return sw_data; | |
} | |
int main() | |
{ | |
while( 1 ) | |
{ | |
cout << get0() << "," << get1() << "," << get2() << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <unistd.h> | |
using namespace std; | |
void set0( bool data ) | |
{ | |
FILE *led; | |
led = fopen("/dev/rtled0", "w" ); | |
if ( data ){ | |
fprintf( led, "1" ); | |
} else { | |
fprintf( led, "0" ); | |
} | |
fclose( led ); | |
} | |
void set1( bool data ) | |
{ | |
FILE *led; | |
led = fopen("/dev/rtled1", "w" ); | |
if ( data ){ | |
fprintf( led, "1" ); | |
} else { | |
fprintf( led, "0" ); | |
} | |
fclose( led ); | |
} | |
void set2( bool data ) | |
{ | |
FILE *led; | |
led = fopen("/dev/rtled2", "w" ); | |
if ( data ){ | |
fprintf( led, "1" ); | |
} else { | |
fprintf( led, "0" ); | |
} | |
fclose( led ); | |
} | |
void set3( bool data ) | |
{ | |
FILE *led; | |
led = fopen("/dev/rtled3", "w" ); | |
if ( data ){ | |
fprintf( led, "1" ); | |
} else { | |
fprintf( led, "0" ); | |
} | |
fclose( led ); | |
} | |
int main() | |
{ | |
while( 1 ) | |
{ | |
set0( true ); | |
set1( true ); | |
set2( true ); | |
set3( true ); | |
usleep( 500 * 1000 ); | |
set0( false ); | |
set1( false ); | |
set2( false ); | |
set3( false ); | |
usleep( 500 * 1000 ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment