int a = 6; int b = 5; int c = 2; int d = 3; int e = 4; int f = 7; int g = 8; int p = 9; void setup() { pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(b, OUTPUT); pinMode(a, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); pinMode(p, OUTPUT); pinMode(A1, INPUT); pinMode(A2, INPUT); Serial.begin(9600); } int num = 1; int xvalue; void loop() { LEDplay(num); delay(1000); xvalue = analogRead(A1); if(xvalue > 1000){ num = num+1; num = num%10; } if(xvalue < 10){ num = num-1; num = num%10; } if(num < 0){ num = 9; } } void LEDplay(int num){ switch (num) { case 0: zero(); break; case 1: one(); break; case 2: two(); break; case 3: three(); break; case 4: four(); break; case 5: five(); break; case 6: six(); break; case 7: seven(); break; case 8: eight(); break; case 9: nine(); break; default: //do nothing break; } } void one(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(p, LOW); } void two(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void three(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void four(){ digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void five(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void six(){ digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void seven(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(p, LOW); } void eight(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void nine(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, LOW); } void zero(){ digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW); digitalWrite(p, LOW); }
Category Archives: C
Arduino Joystick Demo
int joyPin1 = A0; // slider variable connected to analog pin 0 int joyPin2 = A1; // slider variable connected to analog pin 1 int value1 = 0; // variable to read the value from the analog pin 0 int value2 = 0; // variable to read the value from the analog pin 1 void setup() { pinMode(joyPin1, INPUT); pinMode(joyPin2, INPUT); Serial.begin(9600); } void loop() { value1 = analogRead(joyPin1); value2 = analogRead(joyPin2); delay(100); Serial.print("Pin1: "); Serial.print(value1); Serial.print(" Pin2: "); Serial.println(value2); }
Arduino Serial Demo
void setup() { Serial.begin(9600); } int i = 1; void loop() { Serial.println("Each line of code will be delayed by 1 second"); delay(1000); Serial.println("Also, integer i will count upwards by one!"); delay(1000); Serial.println(i); i = i+1; }
Running a C Program from Python
import subprocess cmd = "nameOfCProgram.c" # Example # cmd = HelloWorld.c print ("Hey this is Python Script Running\n") subprocess.call(["gcc",cmd]) #For Compiling subprocess.call("./a.out") #end thats all
The C Code
// DO KEEP BOTH PROGRAMS IN SAME LOCATION // HelloWorld.c #include<stdio.h> int main() { printf("Hello World\n"); printf("This C program Running\n"); return 0; }