GPIO Programming for Raspberry Pi using C

#include 

int main() {
    wiringPiSetup ();
    pinMode(7, OUTPUT);
    for (short i = 1; i <= 5; i++) {
        digitalWrite(7, HIGH);
        delay(1000);
        digitalWrite(7, LOW);
        delay(1000);
    }
    return 0;
}

Compile and run

g++ ledtest.cpp -o ledtest -lwiringPi
sudo ./ledtest
Advertisements

How to Install GLUT to Dev C++

GLUT is a platform-independent OpenGL library. We need to follow the steps below in order to use it on Dev C++

  • glut.h – Copy to C:Dev-CppincludeGL
  • glut32.def – Copy to C:Dev-Cpplib
  • glut32.dll – Copy to C:WINDOWSsystem32

 

Let’s try it:

#include <glgl.h>
#include <glglut.h>
void init(void);
void display(void);

int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,200);
glutCreateWindow("My OpenGL Application");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, -10.0f);
glVertex3f(-1.0f,-1.0f, -10.0f);
glVertex3f( 1.0f,-1.0f, -10.0f);
glEnd();
glutSwapBuffers();
}