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);
}

Source.

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;
}