NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<pthread.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<iobb.h>
#include <fcntl.h>
#include <termios.h>
#include<sys/time.h>
#include<float.h>
#include<sched.h>

pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;


#define START_STOP_PIN 18
#define RESET_PIN 17
#define RED_LIGHT 27
#define GREEN_LIGHT 30


float counter=FLT_MAX-5.0;
int is_counter_initialized=0;
int is_reset_button_pressed=0;
int is_start_stop_button_toggled=0;
int prior1=20;
int prior2=50;

void *start_stop_button_thread(){

while(1){
if(is_high(9,START_STOP_PIN) ){
while(is_high(9,START_STOP_PIN)){
continue;
}
if(is_high(9,RED_LIGHT)){
pin_low(9,RED_LIGHT);
pin_high(9,GREEN_LIGHT);
is_reset_button_pressed=0;
pthread_mutex_lock(&counter_mutex);
while(!is_high(9,START_STOP_PIN) && !is_reset_button_pressed){
printf("33[A33[2KTrTime in seconds %.1fn", counter);
if(counter<20){
counter+=0.01;
}
else{
counter=0;
counter+=0.01;
}
usleep(10000);
}
pthread_mutex_unlock(&counter_mutex);
}
else{
pin_low(9,GREEN_LIGHT);
pin_high(9,RED_LIGHT);
printf("33[A33[2KTrTime in seconds %.2fn", counter);
}
}

}
}

void *reset_button_thread(){
while(1){
if(is_high(9,RESET_PIN)){
while(is_high(9,RESET_PIN)){
continue;
}
is_reset_button_pressed=1;

pthread_mutex_lock(&counter_mutex);
counter=0;
pthread_mutex_unlock(&counter_mutex);
printf("33[A33[2KTrTime in seconds %.2f secondsn", counter);
pin_high(9,RED_LIGHT);
pin_low(9,GREEN_LIGHT);
}
}
}

void initialize_gpios(){
iolib_init();
iolib_setdir(9,START_STOP_PIN,DigitalIn);
iolib_setdir(9,RESET_PIN,DigitalIn);
iolib_setdir(9,RED_LIGHT,DigitalOut);
iolib_setdir(9,GREEN_LIGHT,DigitalOut);
pin_high(9,RED_LIGHT);
pin_low(9,GREEN_LIGHT);
}

int main (){

initialize_gpios();

pthread_t start_stop_button,reset_button;

pthread_attr_t start_stop_attr,reset_button_attr;
int ret1,ret2;
struct sched_param param1,param2;

ret1=pthread_attr_init(&start_stop_attr);
ret2=pthread_attr_init(&reset_button_attr);

ret1=pthread_attr_getschedparam(&start_stop_attr,&param1);
ret2=pthread_attr_getschedparam(&reset_button_attr,&param2);

param1.sched_priority=prior1;
param1.sched_priority=prior2;

ret1=pthread_attr_setschedparam(&start_stop_attr,&param1);
ret2=pthread_attr_setschedparam(&reset_button_attr,&param2);

ret1=pthread_create(&start_stop_button,&start_stop_attr,&start_stop_button_thread,NULL);
ret2=pthread_create(&reset_button,&reset_button_attr,&reset_button_thread,NULL);

pthread_join(start_stop_button,NULL);
pthread_join(reset_button,NULL);

iolib_free();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.