User:Inge Hoonte/arduino notes oct 26: Difference between revisions
Inge Hoonte (talk | contribs) No edit summary |
Inge Hoonte (talk | contribs) No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 28: | Line 28: | ||
for (x=0; x<10; x++){ | for (x=0; x<10; x++){ | ||
for ((i=0; i<3; i++)) { | |||
something; | |||
something | |||
} | |||
void = return value | |||
C doesn't read emptiness | C doesn't read emptiness | ||
int [name] | int [name] | ||
char = a var | char = a var | ||
pat = pattern (also a variable name that you define) | pat = pattern (also a variable name that you define) | ||
[ ] means that a list of variables follows | |||
speakerPin (P is capital, camel case) | speakerPin (P is capital, camel case) | ||
; separates each statement | ; separates each statement | ||
// if you put it before a code, it will not run | // if you put it before a code, it will not run | ||
int speakerPin = 13; | int speakerPin = 13; | ||
//char keycode = 'x' | //char keycode = 'x' | ||
char pat[] = "xxx xx x xx "; | char pat[] = "xxx xx x xx "; | ||
void setup() {} | void setup() {} | ||
void loop () { | void loop () { | ||
if (pat[0] == 'x') { | if (pat[0] == 'x') { | ||
Line 62: | Line 69: | ||
delay 1000 | delay 1000 | ||
} | } | ||
} | } | ||
if pat [0] it starts at first x | if pat [0] it starts at first x | ||
= is assignment statement: what's on left gets assigned to what's on right | = is assignment statement: what's on left gets assigned to what's on right | ||
== asks the q if these two things are equal. answer is true or false. | == asks the q if these two things are equal. answer is true or false. | ||
Line 72: | Line 81: | ||
NOW embed the pattern! | NOW embed the pattern! | ||
while is an if that can go on and on | while is an if that can go on and on | ||
int speakerPin = 13; | int speakerPin = 13; | ||
int thedelay = 1000 | int thedelay = 1000 | ||
//char keycode = 'x' | //char keycode = 'x' | ||
char pat[] = "xxx xx x xx "; | char pat[] = "xxx xx x xx "; | ||
void setup() {} | void setup() {} | ||
void loop () { | void loop () { | ||
int i = 0; | int i = 0; | ||
Line 96: | Line 106: | ||
you have a while loop | you have a while loop | ||
the variable goes in a formula | the variable goes in a formula | ||
you establish the future of i | you establish the future of i | ||
end of loop | end of loop | ||
Line 103: | Line 116: | ||
strlen(pat) = counts the length of the defined pattern automatically | strlen(pat) = counts the length of the defined pattern automatically | ||
MODIFY DIS | |||
int speakerPin = 13; | |||
int thedelay = 100; | |||
//char keycode = 'x' | |||
char pat[] = "xxx xx x xx "; | |||
int patlen = strlen(pat); | |||
void setup() {} | |||
void loop () { | |||
int i = 0; | |||
int i2 = 0; | |||
while (i<patlen) { | |||
i2 = i1+1; | |||
if (pat[i] == 'x') tone(speakerPin, 400, 10); | |||
delay(10); | |||
if (pat2[i] == 'x') tone(speakerPin, 800, 10); | |||
delay (thedelay) | |||
i = i+1; | |||
} | |||
delay (thedelay*10); | |||
} | |||
FIGURE OUT HOW TO MAKE TWO CHANNELS WITH THE CLAPPINGMUSIC LIKE SHIFTING PATTERN |
Latest revision as of 17:01, 26 October 2010
int speakerPin = 13; int thedelay = 100; //char keycode = 'x' char pat[] = "xxx xx x xx "; int patlen = strlen(pat); void setup() {} void loop () { int i = 0; while (i<strlen(pat)) { if (pat[i] == 'x') tone(speakerPin, 400, 10); delay(thedelay); i = i+1; } //can be written in shorthand: /* for (i=0; i<12; i+=1) if (pat[i] == 'x') tone(speakerPin, 400, 10); delay(thedelay); } */ delay (thedelay*10); }
for (x=0; x<10; x++){ for ((i=0; i<3; i++)) { something; something }
void = return value
C doesn't read emptiness
int [name]
char = a var
pat = pattern (also a variable name that you define)
[ ] means that a list of variables follows
speakerPin (P is capital, camel case)
- separates each statement
// if you put it before a code, it will not run
int speakerPin = 13; //char keycode = 'x' char pat[] = "xxx xx x xx "; void setup() {} void loop () { if (pat[0] == 'x') { tone(speakerPin, 500, 10); } delay 1000 } }
if pat [0] it starts at first x
= is assignment statement: what's on left gets assigned to what's on right
== asks the q if these two things are equal. answer is true or false.
tone (output, toonhoogte in Hz, milisec duration)
NOW embed the pattern!
while is an if that can go on and on
int speakerPin = 13; int thedelay = 1000 //char keycode = 'x' char pat[] = "xxx xx x xx "; void setup() {} void loop () { int i = 0; while (i<12) { if (pat[i] == 'x') tone(speakerPin, 400, 10); delay(thedelay); i = i+1; } delay (thedelay*20); }
you have a while loop
the variable goes in a formula
you establish the future of i
end of loop
for (i=0; i<12; i+=1)
strlen(pat) = counts the length of the defined pattern automatically
MODIFY DIS
int speakerPin = 13; int thedelay = 100; //char keycode = 'x' char pat[] = "xxx xx x xx "; int patlen = strlen(pat); void setup() {} void loop () { int i = 0; int i2 = 0; while (i<patlen) { i2 = i1+1; if (pat[i] == 'x') tone(speakerPin, 400, 10); delay(10); if (pat2[i] == 'x') tone(speakerPin, 800, 10); delay (thedelay) i = i+1; } delay (thedelay*10); }
FIGURE OUT HOW TO MAKE TWO CHANNELS WITH THE CLAPPINGMUSIC LIKE SHIFTING PATTERN