This is a code for a bouncing ball on an 8X8 LED. How can i change the code to make it a ping pong game against AI by adding 1 potentionmeter to control it?
#include <TimerOne.h>//this is a library that uses timer 1 of the arduino to trigger interrupts in certain time intervals
//This defines a matrix defining a smiley face for the 8x8 LED
matrix display
#define BALL { \
{1, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}
/*Arduino pin --> Display pin----->8x8 matrix row and column
coordinates (1;1) origin
D2-------------->9---------------------->row 1
D3-------------->10-------------------->col 4
D4-------------->11-------------------->col 6
D5-------------->12--------------------->row 4
D6-------------->13-------------------->col 1
D7-------------->14--------------------->row 2
D8-------------->15-------------------->col 7
D9-------------->16-------------------->col 8
D10------------->4--------------------->col 3
D11------------->3--------------------->col 2
D12------------->2---------------------->row 7
D13------------->1---------------------->row 5
A0 (D14)-------->5---------------------->row 8
A1 (D15)-------->6--------------------->col 5
A2 (D16)-------->7---------------------->row 6
A3 (D17)-------->8---------------------->row 3
*/
//rows:
const int col[8] = {
2,7,17,5,13,16,12,14 };//these are the Arduino pins that connect to
the anodes (1-8) of the LEDs
//columns:
const int row[8] = {
6,11,10,3,15,4,8,9 };//these are the Arduino pins that connect to
the cathodes (1-8) of the LEDs
int x = 0;
int y = 0;
int dx = 1;
int dy = 1;
volatile byte c,r,flag,counter;//interrupt routine variables, they need to be specified as 'volatile'
// 2-dimensional array that contains the currently 'ON' LEDs in
the matrix ('1'='ON'); this is used in the refreshScreen() ISR
below:
byte pattern[8][8] = BALL;
unsigned long previousMillis = 0; //last time we switched
patterns [ms]
unsigned long interval = 1000; //time between switching [ms]
int currentPattern = 0; //0 for "Ball", 1 for "Ball2", 2 for
"Ball3", 3 for "Ball4"
void setup() {
// initialize the row and column pins as outputs
// iterate through the pins:
for (int pin = 0; pin < 8; pin++) {
// initialize the output pins:
pinMode(col[pin], OUTPUT);
digitalWrite(col[pin], HIGH);
pinMode(row[pin], OUTPUT);
digitalWrite(row[pin], LOW);
// take the col pins (i.e. the cathodes) high and the row pins
(anodes) low to ensure that
// the LEDS are off:
}
Timer1.initialize(100); // initialize timer1, and set a 100 us
second period for the interrupt interval (i.e. the ISR will be
called
//every 100 us - this seems to be a good frequency to achieve a
flicker-free LED display.
//experiment with this parameter. If it gets too small the ISR
starts 'eating up' all the processor time, and the main loop
becomes very slow
Timer1.attachInterrupt(refreshScreen); // attaches the
refreshScreen() function as 'Interrupt Service Routine' (ISR) to
the interrupt
//this means that every time 100 us have passed, the
refreshScreen() routine will be called.
}
//main loop...here we can simply busy ourselves with changing
the pattern[][] array; nothing deals with the LED display.
//this is all handled via the ISR
void loop() {
if (x>=7)
{ dx = -1;
dy = random(-1,1);
}
if(x<=0)
{
dx = 1;
dy = random(-1,1);
}
if (y>=7)
{dy = -1;
dx = random(-1,1);
}
if (y<=0)
{ dy = 1;
dx = random(-1,1);
}
pattern[x][y] = 0;
pattern[x+dx][y+dy]=1;
x=x+dx;
y=y+dy;
delay(50);
In: Electrical Engineering
a) Find the discrete Fourier series (DFS) representation of x((n))10, where 10 denotes the period and x(n) is given by:
?(?) = { 1, ??? 0 ≤ ? ≤ 5
0, ??? ??ℎ?? ?
b) For the following two causal sequences (both starting at n = 0), find the circular convolution of minimum size that will produce the same result as
h(n)*x(n). h(n) = {1, 1, 1, 1},
x(n) = {0, 0, 1, 1}
In: Electrical Engineering
The single-phase equivalent-circuit parameters for a three-phase induction motor in ohms-per-phase are
R1=0.17 R2=0.24 X1=1.05 X2=0.87 Xm=82.1 Rc=435
For a slip of 5 percent, and a terminal voltage of 460 V, line to line, calculate:
A) Calculate the motor phase current and input real and reactive power.
B) Calculate the mechanical output power and the power dissipated in the rotor. You might assume that the motor friction and windage losses are 270W
C) Calculate the motor core loss and the motor efficiency.
In: Electrical Engineering
You are a wireless communication specialist working with an
ambitious exploratory firm named PROJECT-SPACE. The firm is
embarking on a huge project to build a human habitat in planet
Mars. In 25 years, PROJECT-SPACE projected that the human habitat
will gradually evolved into a small space city with the population
of 1000 occupants. The initial habitat should be able to
accommodate 15 Martians with consistent, stable and reliable
communication from Mars to the planet Earth command center back in
the capital of the country.
1) How Internet, data rate, noise and bandwidth be sufficient to
achieve stable and reliable communication from Mars to S.I. for 10
people and able to scale up to 1000 people in the future?
2) How Martian atmospheric effect reacts to wireless signals?
3) How do you panned to power up your wireless access-points and
communication device?
4) What would be the time difference, latency (delay) in
communication based on your proposed data rate and bandwidth?
In: Electrical Engineering
Hi.
I'm writing a project about overhead lines, and have a question regarding AC and DC in overhead line.
Is there any different in the electric field if you look at AC and DC
And do you know anything about the simulation program FEMM
Hope you can help me, good day
In: Electrical Engineering
Suppose we have a 10-Hz sinusoidal voltage source, vin(t). Draw the diagram of a circuit that clamps the positive peaks to −4V. The circuit should be composed of ideal diodes, dc voltage sources, and other components as needed. List any constraints that should be observed in selecting component values. Be sure to label the terminals across which the clamped output waveform vo(t) appears.
In: Electrical Engineering
1. is sin(pi/4) causal?
2. is sin(pi/4) stable?
3. is delta(n+1) causal?
4. = ?
5. If function w [ n ] is convolved with , what will the result be?
6. if a system with signal length 4 is convolved with its own system response, what will the length of that signal be?
7. In an LTI system, x[n] * h[n]= y[n]. What is x[n-3] * h[n-2] =?
In: Electrical Engineering
In: Electrical Engineering
Digital arithmetic:
a) Convert +35 to 2-complement
b) Convert -35 to 2-complement
c) Convert 2-complement from 1101 1101 to decimal
d) Add 35 - 35 in binary
In: Electrical Engineering
What are various Pipeline Hazards. Explain each hazard with some common solutions that arebeing employed today?
In: Electrical Engineering
A continuous signal contains the following two components:
x1(t) = 3 cos 20πt
x2(t) = 3 cos 50πt
(a) Find the minimum required sampling rate to avoid
aliasing.
(b) Draw the discrete time signals obtained after sampling, when
sampled with Fs = 100 Hz. Explain the disadvantage(s), if any, of
sampling beyond the Nyquist rate.
(c) Assume the sampling rate is Fs= 40 Hz, which components are
exposed to aliasing effects? Support your answer by showing
“Nyquist intervals” and the aliased frequencies.
In: Electrical Engineering
A low voltage digital device has a low state of 0 V and a high
state of
1.8 V. It generates a signal train of high pulses at a rate of 1
MHz, these
pulses having a 10 ns width and transition times of 100 ps.
(a) Plot the upper bound of its harmonic components up to 10
GHz.
(b) Determine the amplitudes of the third and 101st
harmonics.
(c) Determine the signal bandwidth.
In: Electrical Engineering
Good morning,
Can you introduce some basis knowledge about operational amplifier?
Thank you!!
In: Electrical Engineering
Using a voltmeter and Ammeter, Draw two optimal circuits to measure both low resistance and high resistance. Describe the source of error ( in readings) in both circuits
In: Electrical Engineering
Explain the open loop practical op-amp model
In: Electrical Engineering