Skip to content

Commit

Permalink
Added Arduino 101
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Aldea authored and Andrei Aldea committed Jun 28, 2017
1 parent 2fc6390 commit c73954b
Show file tree
Hide file tree
Showing 2 changed files with 504 additions and 47 deletions.
94 changes: 47 additions & 47 deletions arduino/arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels
#define PIN 5
#define PIN 9

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 39
Expand All @@ -32,25 +32,25 @@ void setup() {

Serial.begin(BAUD);
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code

pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

/* red = promptInt("r?");
green = promptInt("g?");
blue = promptInt("b?");
*/
/* red = promptInt("r?");
green = promptInt("g?");
blue = promptInt("b?");
*/

while(Serial.available()==0) //Wait for user input or serial port to initialize
while (Serial.available() == 0) //Wait for user input or serial port to initialize
{

}
//I should probaly move this to setup and make it a negative but it works so whatever
}

red = Serial.readStringUntil(',').toInt();
Serial.read(); //next character is comma, so skip it using this
Expand All @@ -61,47 +61,47 @@ void loop() {
red = checkBounds(red);
green = checkBounds(green);
blue = checkBounds(blue);


//parse your data here. example:
//double x = Double.parseDouble(first);

//parse your data here. example:
//double x = Double.parseDouble(first);
ardprintf("\n\nDone, set %d, %d, %d \n\n\n", red, green, blue);

// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

for(int i=0;i<NUMPIXELS;i++){
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(red,green,blue)); // Moderately bright green color.
pixels.setPixelColor(i, pixels.Color(red, green, blue)); // Moderately bright green color.

pixels.show(); // This sends the updated pixel color to the hardware.

delay(delayval); // Delay for a period of time (in milliseconds).
}
}

int checkBounds(int val){
if(val > maxBrightness){
val = maxBrightness;
}
int checkBounds(int val) {
if (val > maxBrightness) {
val = maxBrightness;
}

if(val < 0){
val = 0;
}
if (val < 0) {
val = 0;
}

return val; //Return a parsed integer
return val; //Return a parsed integer
}

int promptInt(String prompt){
int promptInt(String prompt) {
int val;
Serial.println(prompt);



val = Serial.parseInt();


val = Serial.parseInt();


}

}

//The following function is bullshit to make sure I can actually print multiple variables in the same line. Aparently implementing prinf correnctly over serial was too much work for the core team....

Expand All @@ -113,45 +113,45 @@ int promptInt(String prompt){

int ardprintf(char *str, ...)
{
int i, count=0, j=0, flag=0;
char temp[ARDBUFFER+1];
for(i=0; str[i]!='\0';i++) if(str[i]=='%') count++;
int i, count = 0, j = 0, flag = 0;
char temp[ARDBUFFER + 1];
for (i = 0; str[i] != '\0'; i++) if (str[i] == '%') count++;

va_list argv;
va_start(argv, count);
for(i=0,j=0; str[i]!='\0';i++)
for (i = 0, j = 0; str[i] != '\0'; i++)
{
if(str[i]=='%')
if (str[i] == '%')
{
temp[j] = '\0';
Serial.print(temp);
j=0;
j = 0;
temp[0] = '\0';

switch(str[++i])
switch (str[++i])
{
case 'd': Serial.print(va_arg(argv, int));
break;
break;
case 'l': Serial.print(va_arg(argv, long));
break;
break;
case 'f': Serial.print(va_arg(argv, double));
break;
break;
case 'c': Serial.print((char)va_arg(argv, int));
break;
break;
case 's': Serial.print(va_arg(argv, char *));
break;
break;
default: ;
};
}
else
else
{
temp[j] = str[i];
j = (j+1)%ARDBUFFER;
if(j==0)
j = (j + 1) % ARDBUFFER;
if (j == 0)
{
temp[ARDBUFFER] = '\0';
Serial.print(temp);
temp[0]='\0';
temp[0] = '\0';
}
}
};
Expand Down
Loading

0 comments on commit c73954b

Please sign in to comment.